﻿using System;
using System.Linq;
using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.Pathing;
using Styx.TreeSharp;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Action = Styx.TreeSharp.Action;

namespace TuanHA_Paladin
{
    public partial class Classname
    {
        #region ArcaneTorrent

        private Composite ArcaneTorrent()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SRacial &&
                _lastInterrupt < DateTime.Now &&
                SpellManager.HasSpell("Arcane Torrent") &&
                SpellManager.Spells["Arcane Torrent"].CooldownTimeLeft.TotalMilliseconds <= _myLatency &&
                GetUnitInterrupt(5, _myLatency, THSettings.Instance.SRebuke, true, true) &&
                _unitInterrupt != null && _unitInterrupt.IsValid,
                new Action(delegate
                               {
                                   if (!Me.IsSafelyFacing(_unitInterrupt))
                                   {
                                       _unitInterrupt.Face();
                                   }
                                   if (Me.IsCasting)
                                   {
                                       SpellManager.StopCasting();
                                   }
                                   if (_unitInterrupt.IsCasting &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds >
                                       _myLatency + THSettings.Instance.SRebuke)
                                   {
                                       return RunStatus.Running;
                                   }
                                   if (_unitInterrupt.IsCasting &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds <
                                       _myLatency + THSettings.Instance.SRebuke &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds > _myLatency)
                                   {
                                       CastSpell("Arcane Torrent", Me);
                                       _lastInterrupt = DateTime.Now + TimeSpan.FromSeconds(1);
                                       return RunStatus.Failure;
                                   }
                                   return RunStatus.Failure;
                               }));
        }

        #endregion

        #region Ardent Defender

        private Composite ArdentDefender()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Ardent Defender") &&
                !Me.Mounted &&
                Me.Combat &&
                !CastingorGCDL() &&
                !Me.HasAura("Divine Shield") &&
                Me.HealthPercent < THSettings.Instance.SArdentDefender &&
                GetSpellCooldown("Ardent Defender").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   CastSpell("Ardent Defender", Me);
                                   return RunStatus.Failure;
                               }));
        }

        #endregion

        #region AttackASAPRotation

        private Composite AttackASAPRotationInstantComp()
        {
            return new Decorator(
                ret => GetUnitAttackASAP(),
                new PrioritySelector(
                    new Decorator(
                        ret =>
                        THSettings.Instance.SCrusaderStrike &&
                        SpellManager.HasSpell("Crusader Strike") &&
                        Attackable(UnitAttackASAP, 5) &&
                        !Blacklist.Contains(UnitAttackASAP.Guid, BlacklistFlags.All) &&
                        !CastingorGCDL() &&
                        FacingOverride(UnitAttackASAP) &&
                        GetSpellCooldown("Crusader Strike").TotalMilliseconds <= _myLatency,
                        new Action(delegate
                                       {
                                           CastSpell("Crusader Strike", UnitAttackASAP);
                                           UnitAttackASAP = null;
                                       })),
                    new Decorator(
                        ret =>
                        THSettings.Instance.SJudgment &&
                        SpellManager.HasSpell("Judgment") &&
                        Attackable(UnitAttackASAP, 30 + _bonusJudgementRange) &&
                        !Blacklist.Contains(UnitAttackASAP.Guid, BlacklistFlags.All) &&
                        !InvulnerableMagic(UnitAttackASAP) &&
                        !CastingorGCDL() &&
                        GetSpellCooldown("Judgment").TotalMilliseconds <= _myLatency &&
                        AttackableValid(UnitAttackASAP),
                        new Action(delegate
                                       {
                                           CastSpell("Judgment", UnitAttackASAP);
                                           UnitAttackASAP = null;
                                       })),
                    new Decorator(
                        ret =>
                        !SpellManager.HasSpell("Eternal Flame") &&
                        SpellManager.HasSpell("Word of Glory") &&
                        Attackable(UnitAttackASAP, 40) &&
                        !Blacklist.Contains(UnitAttackASAP.Guid, BlacklistFlags.All) &&
                        HasGlyph.Contains("41107") && //Glyph of Harsh Words
                        !InvulnerableMagic(UnitAttackASAP) &&
                        (Me.CurrentHolyPower >= 1 || Me.HasAura(" Divine Purpose")) &&
                        (UnitHeal == null ||
                         UnitHeal != null && UnitHeal.HealthPercent > THSettings.Instance.SWordofGlory) &&
                        FacingOverride(UnitAttackASAP) &&
                        AttackableValid(UnitAttackASAP) &&
                        !CastingorGCDL(),
                        new Action(delegate
                                       {
                                           SafelyFacingTarget(UnitAttackASAP);
                                           CastSpell("Word of Glory", UnitAttackASAP);
                                           UnitAttackASAP = null;
                                       })),
                    new Decorator(
                        ret =>
                        THSettings.Instance.SExorcism &&
                        SpellManager.HasSpell("Exorcism") &&
                        Attackable(UnitAttackASAP, 40) &&
                        !Blacklist.Contains(UnitAttackASAP.Guid, BlacklistFlags.All) &&
                        AttackableValid(UnitAttackASAP) &&
                        FacingOverride(UnitAttackASAP) &&
                        !InvulnerableMagic(UnitAttackASAP) &&
                        (Me.CurrentHolyPower < Me.MaxHolyPower || !UnitAttackASAP.IsWithinMeleeRange) &&
                        !CastingorGCDL() &&
                        GetSpellCooldown("Exorcism").TotalMilliseconds <= _myLatency,
                        new Action(delegate
                                       {
                                           SafelyFacingTarget(UnitAttackASAP);
                                           CastSpell("Exorcism", UnitAttackASAP);
                                           UnitAttackASAP = null;
                                       })),
                    new Decorator(
                        ret =>
                        //_lastCastSpell != "Holy Shock" &&
                        THSettings.Instance.SHolyShockOffensive &&
                        SpellManager.HasSpell("Holy Shock") &&
                        Attackable(UnitAttackASAP, 40) &&
                        !Blacklist.Contains(UnitAttackASAP.Guid, BlacklistFlags.All) &&
                        !InvulnerableMagic(UnitAttackASAP) &&
                        (UnitHeal == null || UnitHeal.HealthPercent > THSettings.Instance.SDoNotHealAbove) &&
                        FacingOverride(UnitAttackASAP) &&
                        !CastingorGCDL() &&
                        GetSpellCooldown("Holy Shock").TotalMilliseconds <= _myLatency,
                        new Action(delegate
                                       {
                                           SafelyFacingTarget(UnitAttackASAP);
                                           CastSpell("Holy Shock", UnitAttackASAP);
                                           //UnitAttackASAP = null;
                                       }))
                    ))
                ;
        }

        private Composite AttackASAPRotationCastComp()
        {
            return new Decorator(
                ret => GetUnitAttackASAP(),
                new PrioritySelector(
                    new Decorator(
                        ret =>
                        THSettings.Instance.SDenounce &&
                        SpellManager.HasSpell("Denounce") &&
                        !Blacklist.Contains(UnitAttackASAP.Guid, BlacklistFlags.All) &&
                        Attackable(UnitAttackASAP, 30) &&
                        !InvulnerableMagic(UnitAttackASAP) &&
                        !Me.IsMoving &&
                        FacingOverride(UnitAttackASAP) &&
                        AttackableValid(UnitAttackASAP) &&
                        !CastingorGCDL(),
                        new Action(delegate
                                       {
                                           WoWMovement.ConstantFace(UnitAttackASAP.Guid);
                                           IsConstantFace = true;
                                           CastSpell("Denounce", UnitAttackASAP);
                                           UnitAttackASAP = null;
                                       }))
                    ));
        }

        #endregion

        #region AttackRotationHoly

        private Composite AttackRotationHolyInstantComp()
        {
            return new PrioritySelector(
                HolyPrismAttackHoly(),
                ExecutionSentenceAttackHoly(),
                new Decorator(
                    ret =>
                    //THSettings.Instance.SJudgment &&
                    SpellManager.HasSpell("Judgment") &&
                    !CastingorGCDL() &&
                    UnitHeal != null &&
                    UnitHeal.IsValid &&
                    UnitHeal.HealthPercent > THSettings.Instance.SPriorityHeal &&
                    GetUnitJudgment() &&
                    !Blacklist.Contains(UnitJudgment.Guid, BlacklistFlags.All) &&
                    UnitJudgment != null &&
                    UnitJudgment.IsValid &&
                    UnitJudgment.Distance < 30 + _bonusJudgementRange &&
                    GetSpellCooldown("Judgment").TotalMilliseconds <= _myLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Judgment UnitJudgment");
                                       CastSpell("Judgment", UnitJudgment);
                                       UnitJudgment = null;
                                   })),
                new Decorator(
                    ret =>
                    SpellManager.HasSpell("Word of Glory") &&
                    !SpellManager.HasSpell("Eternal Flame") &&
                    Attackable(UnitAttack, 40) &&
                    !Blacklist.Contains(UnitAttack.Guid, BlacklistFlags.All) &&
                    (Me.ManaPercent > THSettings.Instance.SManaforDPS ||
                     UnitAttack.HealthPercent < 30) &&
                    HasGlyph.Contains("41107") && //Glyph of Harsh Words
                    (Me.CurrentHolyPower >= 3 ||
                     Me.HasAura(" Divine Purpose")) &&
                    (UnitHeal == null ||
                     UnitHeal != null &&
                     UnitHeal.HealthPercent > THSettings.Instance.SWordofGlory) &&
                    !InvulnerableMagic(UnitAttack) &&
                    FacingOverride(UnitAttack) &&
                    UnitHeal != null &&
                    UnitHeal.IsValid &&
                    UnitHeal.HealthPercent > THSettings.Instance.SPriorityHeal &&
                    !CastingorGCDL(),
                    new Action(delegate
                                   {
                                       SafelyFacingTarget(UnitAttack);
                                       //Logging.Write(LogLevel.Diagnostic, "Word of Glory UnitAttack");
                                       CastSpell("Word of Glory", UnitAttack);
                                       UnitAttack = null;
                                   })),
                new Decorator(
                    ret =>
                    //_lastCastSpell != "Holy Shock" &&
                    THSettings.Instance.SHolyShockOffensive &&
                    SpellManager.HasSpell("Holy Shock") &&
                    Attackable(UnitAttack, 40) &&
                    !Blacklist.Contains(UnitAttack.Guid, BlacklistFlags.All) &&
                    (Me.ManaPercent > THSettings.Instance.SManaforDPS ||
                     UnitAttack.HealthPercent < 30) &&
                    (UnitHeal == null ||
                     UnitHeal != null &&
                     UnitHeal.IsValid &&
                     UnitHeal.HealthPercent > THSettings.Instance.SDoNotHealAbove) &&
                    !InvulnerableMagic(UnitAttack) &&
                    FacingOverride(UnitAttack) &&
                    !CastingorGCDL() &&
                    SpellManager.Spells["Holy Shock"].CooldownTimeLeft.TotalMilliseconds <= 0,
                    new Action(delegate
                                   {
                                       SafelyFacingTarget(UnitAttack);
                                       //Logging.Write(LogLevel.Diagnostic, "Holy Shock UnitAttack");
                                       CastSpell("Holy Shock", UnitAttack);
                                       //UnitAttack = null;
                                   }))
                );
        }

        private Composite AttackRotationHolyCastComp()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    THSettings.Instance.SDenounce &&
                    SpellManager.HasSpell("Denounce") &&
                    Attackable(UnitAttack, 30) &&
                    (UnitAttack.IsPlayer || UnitAttack.HealthPercent < 30) &&
                    !Blacklist.Contains(UnitAttack.Guid, BlacklistFlags.All) &&
                    (Me.ManaPercent > THSettings.Instance.SManaforDPS ||
                     UnitAttack.HealthPercent < 30 ||
                     Me.HasAura("Glyph of Denouce")) &&
                    !Me.IsMoving &&
                    !IsOverrideModeOn &&
                    !InvulnerableMagic(UnitAttack) &&
                    UnitHeal != null &&
                    UnitHeal.IsValid &&
                    UnitHeal.HealthPercent > THSettings.Instance.SPriorityHeal &&
                    !CastingorGCDL(),
                    new Action(delegate
                                   {
                                       WoWMovement.ConstantFace(UnitAttack.Guid);
                                       IsConstantFace = true;
                                       CastSpell("Denounce", UnitAttack);
                                       UnitAttack = null;
                                   }))
                );
        }

        #endregion

        #region Avenger's Shield

        private Composite AvengersShield()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SAvengersShield &&
                SpellManager.HasSpell("Avenger's Shield") &&
                !Me.Mounted &&
                Attackable(Me.CurrentTarget, 30) &&
                FacingOverride(Me.CurrentTarget) &&
                !InvulnerableMagic(Me.CurrentTarget) &&
                !CastingorGCDL() &&
                GetSpellCooldown("Avenger's Shield").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   SafelyFacingTarget(Me.CurrentTarget);
                                   CastSpell("Avenger's Shield", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region AvengersShieldInterrupt

        private Composite AvengersShieldInterrupt()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SHammerofJustice != 0 &&
                _lastInterrupt < DateTime.Now &&
                SpellManager.HasSpell("Avenger's Shield") &&
                UnitHeal != null &&
                UnitHeal.IsValid &&
                UnitHeal.HealthPercent > THSettings.Instance.SUrgentHeal &&
                SpellManager.Spells["Avenger's Shield"].CooldownTimeLeft.TotalMilliseconds <= _myLatency &&
                GetUnitInterrupt(30, _myLatency, THSettings.Instance.SHammerofJustice, false, false) &&
                _unitInterrupt != null && _unitInterrupt.IsValid,
                new Action(delegate
                               {
                                   if (Me.IsCasting)
                                   {
                                       SpellManager.StopCasting();
                                   }
                                   if (_unitInterrupt.IsCasting &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds >
                                       _myLatency + THSettings.Instance.SHammerofJustice)
                                   {
                                       return RunStatus.Running;
                                   }
                                   if (_unitInterrupt.IsCasting &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds <
                                       _myLatency + THSettings.Instance.SHammerofJustice &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds > _myLatency)
                                   {
                                       CastSpell("Avenger's Shield", _unitInterrupt);
                                       _lastInterrupt = DateTime.Now + TimeSpan.FromSeconds(1);
                                       return RunStatus.Success;
                                   }
                                   return RunStatus.Failure;
                               }));
        }

        #endregion

        #region Avenger's Shield Lose Threat

        private Composite AvengersShieldLoseThreat()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SAvengersShield &&
                SpellManager.HasSpell("Avenger's Shield") &&
                Me.Combat &&
                GetUnitReckoningProtection() &&
                _unitReckoningProtection != null &&
                _unitReckoningProtection.IsValid &&
                !CastingorGCDL() &&
                GetSpellCooldown("Avenger's Shield").TotalMilliseconds <= _myLatency,
                new Action(
                    ret =>
                        {
                            SafelyFacingTarget(_unitReckoningProtection);
                            CastSpell("Avenger's Shield", _unitReckoningProtection);
                            _unitReckoning = null;
                        })
                );
        }

        #endregion

        #region AvengersShieldProtection

        private WoWUnit _unitAvengersShielLowestThreat;

        private bool GetAvengersShieldLowestThreatUnit()
        {
            _unitAvengersShielLowestThreat = null;

            //using (StyxWoW.Memory.AcquireFrame())
            {
                _unitAvengersShielLowestThreat = (from unit in NearbyUnFriendlyUnits
                                                  orderby unit.ThreatInfo.RawPercent ascending
                                                  where Me.Combat
                                                  where FacingOverride(unit)
                                                  where Me.CurrentMap.IsDungeon || Me.CurrentMap.IsRaid
                                                  where unit.Combat
                                                  //Make sure dont taunt off another tank
                                                  where !unit.CurrentTarget.HasAura("Vengeance")
                                                  where GetMinDistance(unit) < 30
                                                  where unit.InLineOfSpellSight
                                                  select unit).FirstOrDefault();
                return _unitAvengersShielLowestThreat != null;
            }
        }

        private Composite AvengersShieldLowestThreatUnit()
        {
            return new Decorator(
                ret =>
                //THSettings.Instance.STaunt &&
                SpellManager.HasSpell("Avenger's Shield") &&
                !Me.Mounted &&
                GetAvengersShieldLowestThreatUnit() &&
                _unitAvengersShielLowestThreat != null &&
                _unitAvengersShielLowestThreat.IsValid &&
                GetSpellCooldown("Avenger's Shield").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   SafelyFacingTarget(_unitAvengersShielLowestThreat);
                                   CastSpell("Avenger's Shield", _unitAvengersShielLowestThreat);
                               })
                );
        }

        private Composite AvengersShieldGrandCrusader()
        {
            return new Decorator(
                ret =>
                //THSettings.Instance.STaunt &&
                SpellManager.HasSpell("Avenger's Shield") &&
                !Me.Mounted &&
                GetAvengersShieldLowestThreatUnit() &&
                _unitAvengersShielLowestThreat != null &&
                _unitAvengersShielLowestThreat.IsValid &&
                Me.HasAura("Grand Crusader") &&
                GetSpellCooldown("Avenger's Shield").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   SafelyFacingTarget(_unitAvengersShielLowestThreat);
                                   CastSpell("Avenger's Shield", _unitAvengersShielLowestThreat);
                               })
                );
        }

        #endregion

        #region AvengingWrath

        private Composite AvengingWrath()
        {
            return new Decorator(
                ret =>
                //_lastCastSpell != "Avenging Wrath" &&
                Healable(UnitHeal) &&
                UnitHeal.Combat &&
                !UnitHeal.IsPet &&
                !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
                (UnitHeal.HealthPercent <= THSettings.Instance.SAvengingWrathHP &&
                 LastBurstCalled < DateTime.Now ||
                 THSettings.Instance.SBurst) &&
                //IsMeorFocus(UnitHeal) && 
                !Me.HasAura("Divine Shield") &&
                GetSpellCooldown("Avenging Wrath").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   if (Me.IsCasting && !IsHealing())
                                   {
                                       SpellManager.StopCasting();
                                   }
                                   LastBurstCalled = DateTime.Now +
                                                     TimeSpan.FromMilliseconds(THSettings.Instance.BurstDelay);
                                   CastSpell("Avenging Wrath", Me);
                                   return RunStatus.Failure;
                               }));
        }

        #endregion

        #region AvengingWrathBurstRet

        private Composite AvengingWrathBurstRet()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SBurst &&
                THSettings.Instance.SAvengingWrath &&
                SpellManager.HasSpell("Avenging Wrath") &&
                SpellManager.HasSpell("Guardian of Ancient Kings") &&
                !Me.Mounted &&
                Attackable(Me.CurrentTarget, 15) &&
                !Me.CurrentTarget.IsFlying &&
                !CastingorGCDL() &&
                GetSpellCooldown("Guardian of Ancient Kings").TotalSeconds < 294 &&
                GetSpellCooldown("Guardian of Ancient Kings").TotalSeconds > 0 &&
                GetSpellCooldown("Avenging Wrath").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Avenging Wrath", Me);
                                   return RunStatus.Failure;
                               })
                );
        }

        #endregion

        #region Beacon of Light

        //private WoWUnit _unitHaveBeacon;

        //private bool GetUnitHaveBeacon()
        //{
        //    UnitHaveBeacon = null;
        //    //using (StyxWoW.Memory.AcquireFrame())
        //    {
        //        UnitHaveBeacon = (from unit in FarFriendlyUnits
        //                          where MyAura("Beacon of Light", unit)
        //                          select unit).FirstOrDefault();

        //        return UnitHaveBeacon != null;
        //    }
        //}
        private WoWUnit _unitBeaconSecond;

        private void BeaconHealSecondUnit(WoWUnit u)
        {
            if (THSettings.Instance.SEternalFlameBlanketHolyPower > 0)
            {
                return;
            }

            if (!SpellManager.HasSpell("Beacon of Light"))
            {
                //Logging.Write(LogLevel.Diagnostic, "BeaconHealSecondUnit: No Spell Beacon of Light");
                return;
            }

            if (!THSettings.Instance.SBeaconofLight)
            {
                //Logging.Write(LogLevel.Diagnostic, "BeaconHealSecondUnit: SBeaconofLight Unchecked");
                return;
            }

            if (u == null)
            {
                return;
            }
            if (!HasGlyph.Contains("63218")) //"Glyph of Beacon of Light")
            {
                //Logging.Write(LogLevel.Diagnostic, "BeaconHealSecondUnit: No Glyph of Beacon of Light");
                return;
            }

            _unitBeaconSecond = null;

            //using (StyxWoW.Memory.AcquireFrame())
            {
                _unitBeaconSecond = (from unit in FarFriendlyPlayers
                                     where !Blacklist.Contains(unit.Guid, BlacklistFlags.All)
                                     orderby unit.HealthPercent ascending
                                     //If no heal target, put beacon on Tank
                                     where unit.IsPlayer
                                     where
                                         unit != u &&
                                         unit.HasAura("Vengeance") &&
                                         (Me.CurrentMap.IsDungeon || Me.CurrentMap.IsRaid) ||
                                         unit.HealthPercent < THSettings.Instance.SDoNotHealAbove
                                     where !MyAura("Beacon of Light", unit)
                                     where GetMinDistance(unit) < 60
                                     where !DebuffDoNotHeal(unit)
                                     where unit.InLineOfSpellSight
                                     select unit).FirstOrDefault();
            }

            if (!Me.Mounted &&
                _unitBeaconSecond != null &&
                _unitBeaconSecond.IsValid &&
                GetSpellCooldown("Beacon of Light").TotalMilliseconds <= _myLatency)
            {
                SpellManager.Cast("Beacon of Light", _unitBeaconSecond);
                Logging.Write(DateTime.Now.ToString("ss:fff") + " HP: " +
                              Math.Round(Me.HealthPercent) + "% Mana: " +
                              Math.Round(Me.ManaPercent) +
                              "% Beacon of Light to Heal Second Unit " +
                              _unitBeaconSecond.Class + " " +
                              Math.Round(_unitBeaconSecond.Distance) + "y " +
                              Math.Round(_unitBeaconSecond.HealthPercent) + "% hp");
            }
            else if (!Me.Mounted &&
                     _unitBeaconSecond == null &&
                     !MyAura("Beacon of Light", Me))
            {
                SpellManager.Cast("Beacon of Light", Me);
            }
        }

        private WoWUnit _unitBeaconFirst;

        private Composite BeaconHealFirstUnit()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SEternalFlameBlanketHolyPower > 0 &&
                SpellManager.HasSpell("Beacon of Light") &&
                !Me.Mounted &&
                THSettings.Instance.SBeaconofLight &&
                GetUnitBeaconFirst() &&
                _unitBeaconFirst != null &&
                _unitBeaconFirst.IsValid &&
                !MyAura("Beacon of Light", _unitBeaconFirst) &&
                GetSpellCooldown("Beacon of Light").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   CastSpell("Beacon of Light", _unitBeaconFirst);
                                   _unitBeaconFirst = null;
                                   return RunStatus.Failure;
                               })
                );
        }

        private bool GetUnitBeaconFirst()
        {
            _unitBeaconFirst = null;

            //using (StyxWoW.Memory.AcquireFrame())
            {
                _unitBeaconFirst = (from unit in FarFriendlyPlayers
                                    where !Blacklist.Contains(unit.Guid, BlacklistFlags.All)
                                    orderby unit.HealthPercent ascending
                                    //If no heal target, put beacon on Tank
                                    where unit.IsPlayer
                                    where
                                        unit.HasAura("Vengeance") &&
                                        (Me.CurrentMap.IsDungeon || Me.CurrentMap.IsRaid) ||
                                        unit.HealthPercent < THSettings.Instance.SDoNotHealAbove
                                    where GetMinDistance(unit) < 60
                                    where !DebuffDoNotHeal(unit)
                                    where unit.InLineOfSpellSight
                                    select unit).FirstOrDefault();
            }

            if (_unitBeaconFirst == null && !MyAura("Beacon of Light", Me))
            {
                _unitBeaconFirst = Me;
            }
            return _unitBeaconFirst != null;
        }

        private void BeaconBuildHolyPower(WoWUnit u)
        {
            if (!SpellManager.HasSpell("Beacon of Light"))
            {
                //Logging.Write(LogLevel.Diagnostic, "BeaconBuildHolyPower: No Spell Beacon of Light");
                return;
            }

            if (!THSettings.Instance.SBeaconofLight)
            {
                //Logging.Write(LogLevel.Diagnostic, "BeaconBuildHolyPower: SBeaconofLight Unchecked");
                return;
            }

            if (!HasGlyph.Contains("63218")) //"Glyph of Beacon of Light")
            {
                //Logging.Write(LogLevel.Diagnostic, "BeaconBuildHolyPower: No Glyph of Beacon of Light");
                return;
            }

            if (!MyAura("Beacon of Light", u) &&
                GetSpellCooldown("Beacon of Light").TotalMilliseconds <= _myLatency)
            {
                {
                    SpellManager.Cast("Beacon of Light", u);
                    Logging.Write(DateTime.Now.ToString("ss:fff") + " HP: " +
                                  Math.Round(Me.HealthPercent) + "% Mana: " +
                                  Math.Round(Me.ManaPercent) +
                                  "% Beacon of Light to build Holy Power " +
                                  u.Class +
                                  " " + Math.Round(u.Distance) + "y " +
                                  Math.Round(u.HealthPercent) + "% hp");
                }
            }
        }

        #endregion

        #region BlindingLight

        private Composite BlindingLight()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SBlindingLight != 0 &&
                _lastInterrupt < DateTime.Now &&
                SpellManager.HasSpell("Blinding Light") &&
                UnitHeal != null &&
                UnitHeal.IsValid &&
                UnitHeal.HealthPercent > THSettings.Instance.SUrgentHeal &&
                SpellManager.Spells["Blinding Light"].CooldownTimeLeft.TotalMilliseconds <= _myLatency &&
                GetUnitInterrupt(10, _myLatency, THSettings.Instance.SHammerofJustice, false, false) &&
                _unitInterrupt != null && _unitInterrupt.IsValid,
                new Action(delegate
                               {
                                   if (Me.IsCasting)
                                   {
                                       SpellManager.StopCasting();
                                   }
                                   if (_unitInterrupt.IsCasting &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds >
                                       _myLatency + THSettings.Instance.SBlindingLight)
                                   {
                                       return RunStatus.Running;
                                   }
                                   if (_unitInterrupt.IsCasting &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds <
                                       _myLatency + THSettings.Instance.SHammerofJustice &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds > _myLatency)
                                   {
                                       CastSpell("Blinding Light", Me);
                                       _lastInterrupt = DateTime.Now + TimeSpan.FromSeconds(1);
                                       return RunStatus.Success;
                                   }
                                   return RunStatus.Failure;
                               }));
        }

        #endregion

        #region Buff

        private Composite BuffRotation()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    THSettings.Instance.SBuff &&
                    THSettings.Instance.SPreferMight &&
                    SpellManager.HasSpell("Blessing of Might") &&
                    !Me.Mounted &&
                    UnitHeal != null &&
                    UnitHeal.IsValid &&
                    (UnitHeal == Me || Me.CurrentMap.IsArena) &&
                    !UnitHeal.HasAura("Blessing of Might") &&
                    !UnitHeal.HasAura("Grace of Air") &&
                    !UnitHeal.HasAura("Roar of Courage") &&
                    !UnitHeal.HasAura("Spirit Beast Blessing") &&
                    !CastingorGCDL(),
                    new Action(delegate { CastSpell("Blessing of Might", Me); })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SBuff &&
                    THSettings.Instance.SPreferMight &&
                    SpellManager.HasSpell("Blessing of Kings") &&
                    !Me.Mounted &&
                    UnitHeal != null &&
                    UnitHeal.IsValid &&
                    (UnitHeal == Me || Me.CurrentMap.IsArena) &&
                    (UnitHeal.HasAura("Blessing of Might") && !MyAura("Blessing of Might", UnitHeal) ||
                     UnitHeal.HasAura("Grace of Air") ||
                     UnitHeal.HasAura("Roar of Courage") ||
                     UnitHeal.HasAura("Spirit Beast Blessing")) &&
                    !UnitHeal.HasAura("Blessing of Kings") &&
                    !UnitHeal.HasAura("Embrace of the Shale Spider") &&
                    !UnitHeal.HasAura("Legacy of the Emperor") &&
                    !UnitHeal.HasAura("Mark of the Wild") &&
                    !CastingorGCDL(),
                    new Action(delegate { CastSpell("Blessing of Kings", Me); })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SBuff &&
                    THSettings.Instance.SPreferKings &&
                    SpellManager.HasSpell("Blessing of Kings") &&
                    !Me.Mounted &&
                    UnitHeal != null &&
                    UnitHeal.IsValid &&
                    (UnitHeal == Me || Me.CurrentMap.IsArena) &&
                    !UnitHeal.HasAura("Blessing of Kings") &&
                    !UnitHeal.HasAura("Legacy of the Emperor") &&
                    !UnitHeal.HasAura("Mark of the Wild") &&
                    !UnitHeal.HasAura("Embrace of the Shale Spider") &&
                    !CastingorGCDL(),
                    new Action(delegate { CastSpell("Blessing of Kings", Me); })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SBuff &&
                    THSettings.Instance.SPreferKings &&
                    SpellManager.HasSpell("Blessing of Might") &&
                    !Me.Mounted &&
                    UnitHeal != null &&
                    UnitHeal.IsValid &&
                    (UnitHeal == Me || Me.CurrentMap.IsArena) &&
                    (UnitHeal.HasAura("Blessing of Kings") && !MyAura("Blessing of Kings", UnitHeal) ||
                     UnitHeal.HasAura("Legacy of the Emperor") ||
                     UnitHeal.HasAura("Embrace of the Shale Spider") ||
                     UnitHeal.HasAura("Mark of the Wild")) &&
                    !UnitHeal.HasAura("Blessing of Might") &&
                    !UnitHeal.HasAura("Grace of Air") &&
                    !UnitHeal.HasAura("Roar of Courage") &&
                    !UnitHeal.HasAura("Spirit Beast Blessing") &&
                    !CastingorGCDL(),
                    new Action(delegate { CastSpell("Blessing of Might", Me); }))
                );
        }

        #endregion

        #region BubbleFlashofLightRet

        private Composite BubbleFlashofLightRet()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Flash of Light") &&
                !Me.Mounted &&
                Me.CurrentMana > Me.MaxMana*0.378 &&
                !Me.CurrentMap.IsDungeon &&
                !Me.CurrentMap.IsRaid &&
                !IsOverrideModeOn &&
                !CastingorGCDL() &&
                (Me.HasAura("Divine Shield") ||
                 Me.HasAura("Devotion Aura") ||
                 Me.HasAura("Hand of Protection")) &&
                Me.HealthPercent < THSettings.Instance.SDoNotHealAbove,
                new Action(delegate
                               {
                                   if (Me.IsMoving)
                                   {
                                       Navigator.PlayerMover.MoveStop();
                                       WoWMovement.MoveStop();
                                   }
                                   //Logging.Write(LogLevel.Diagnostic, "BubbleFlashofLightRet");
                                   DoNotMove = DateTime.Now + TimeSpan.FromSeconds(1);
                                   CastSpell("Flash of Light", Me);
                                   if (DoNotMove < DateTime.Now)
                                   {
                                       return RunStatus.Running;
                                   }
                                   return RunStatus.Success;
                               })
                );
        }

        #endregion

        #region BubbleFlashofLightRet

        private Composite CancelBubbleProtection()
        {
            return new Decorator(
                ret =>
                !Me.Mounted &&
                (Me.HasAura("Divine Shield") ||
                 Me.HasAura("Hand of Protection")) &&
                Me.HealthPercent > THSettings.Instance.SPriorityHeal,
                new Action(delegate
                               {
                                   Lua.DoString("RunMacroText('/cancelaura " + WoWSpell.FromId(642) + "');");
                                   Lua.DoString("RunMacroText('/cancelaura " + WoWSpell.FromId(1022) + "');");
                                   //Lua.DoString("CancelUnitBuff(\"Player\",\"Divine Shield\")");
                                   //Lua.DoString("CancelUnitBuff(\"Player\",\"Hand of Protection\")");
                                   return RunStatus.Failure;
                               })
                );
        }

        #endregion

        #region CleanseFriendlyASAPComp

        private WoWUnit _playerFriendlyCleanseASAP;

        private bool GetPlayerFriendlyCleanseASAP()
        {
            _playerFriendlyCleanseASAP = null;

            if (!THSettings.Instance.SCleanseASAP || !Me.Combat)
            {
                return false;
            }
            /*CombatAdvanced Start*/
            //using (StyxWoW.Memory.AcquireFrame())
            {
                _playerFriendlyCleanseASAP = (from unit in NearbyFriendlyPlayers
                                              orderby TalentSort(unit) descending
                                              where DebuffCC(Me) <= 0
                                              where HealableValid(unit)
                                              where !DebuffDoNotCleanse(unit)
                                              where DebuffCCCleanseASAP(unit) > 0
                                                    || DebuffCCBreakonDamage(unit) && DotAll(unit) <= 0
                                              select unit).FirstOrDefault();
            }
            return _playerFriendlyCleanseASAP != null;
        }

        private Composite CleanseFriendlyASAPComp()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    SpellManager.HasSpell("Cleanse") &&
                    UnitHeal != null &&
                    UnitHeal.IsValid &&
                    UnitHeal.HealthPercent > THSettings.Instance.SPriorityHeal &&
                    (Me.IsCasting || !CastingorGCDL()) &&
                    GetPlayerFriendlyCleanseASAP() &&
                    _playerFriendlyCleanseASAP != null &&
                    _playerFriendlyCleanseASAP.IsValid &&
                    GetSpellCooldown("Cleanse").TotalMilliseconds <= _myLatency,
                    new Action(delegate
                                   {
                                       SpellManager.StopCasting();
                                       CastSpell("Cleanse", _playerFriendlyCleanseASAP);
                                       //Lua.DoString("RunMacroText(\"/s Cleanse " + PlayerFriendlyCleanseASAP.Name +
                                       //             " ASAP\")");
                                       _playerFriendlyCleanseASAP = null;
                                       Logging.Write("Cleanse ASAP");
                                   }))
                )
                ;
        }

        #endregion

        #region CleanseFriendlyComp

        private WoWUnit _playerFriendlyCleanse;

        private bool GetPlayerFriendlyCleanse()
        {
            _playerFriendlyCleanse = null;

            if (THSettings.Instance.SCleanseDebuffNumber == 0 || !Me.Combat)
            {
                return false;
            }
            /*CombatAdvanced Start*/
            //using (StyxWoW.Memory.AcquireFrame())
            {
                _playerFriendlyCleanse = (from unit in NearbyFriendlyPlayers
                                          where HealableValid(unit)
                                          where !DebuffDoNotCleanse(unit)
                                          where CountDebuff(unit) >= THSettings.Instance.SCleanseDebuffNumber
                                          orderby CountDebuff(unit) descending
                                          select unit).FirstOrDefault();
            }
            /*CombatAdvanced End*/

            return _playerFriendlyCleanse != null;
        }

        private Composite CleanseFriendlyComp()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    SpellManager.HasSpell("Cleanse") &&
                    UnitHeal != null &&
                    UnitHeal.IsValid &&
                    UnitHeal.HealthPercent > THSettings.Instance.SPriorityHeal &&
                    Me.ManaPercent > 30 &&
                    (Me.IsCasting || !CastingorGCDL()) &&
                    GetPlayerFriendlyCleanse() && _playerFriendlyCleanse.IsValid &
                    GetSpellCooldown("Cleanse").TotalMilliseconds <= _myLatency,
                    new Action(delegate
                                   {
                                       SpellManager.StopCasting();
                                       CastSpell("Cleanse", _playerFriendlyCleanse);
                                       //Lua.DoString("RunMacroText(\"/s Cleanse " + PlayerFriendlyCleanseASAP.Name +
                                       //             "\")");
                                       Logging.Write("Cleanse Debuff");
                                       _playerFriendlyCleanse = null;
                                   }))
                );
        }

        #endregion

        #region CleanseMe

        private Composite CleanseMe()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    THSettings.Instance.SCleanseDebuffNumber > 0 &&
                    Me.ManaPercent > 30 &&
                    UnitHeal != null && UnitHeal.IsValid && UnitHeal.HealthPercent > THSettings.Instance.SUrgentHeal &&
                    (Me.IsCasting && !IsHealing() || !CastingorGCDL()) &&
                    (DebuffRootCanCleanse(Me) > 0 ||
                     CountDebuff(Me) >= THSettings.Instance.SCleanseDebuffNumber) &&
                    !DebuffDoNotCleanse(Me) &&
                    GetSpellCooldown("Cleanse").TotalMilliseconds <= _myLatency,
                    new Action(delegate
                                   {
                                       if (Me.IsCasting)
                                       {
                                           SpellManager.StopCasting();
                                       }
                                       CastSpell("Cleanse", Me);
                                   }))
                );
        }

        #endregion

        #region Consecration

        private Composite Consecration()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SConsecration &&
                SpellManager.HasSpell("Consecration") &&
                !Me.Mounted &&
                !HasGlyph.Contains("41099") &&
                Me.ManaPercent > 50 &&
                CountEneyNeary(Me, 10) > 0 &&
                !CastingorGCDL() &&
                GetSpellCooldown("Consecration").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   ////Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Consecration", Me);
                               })
                );
        }

        #endregion

        #region ConsecrationGlyph

        private Composite ConsecrationGlyph()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SConsecration &&
                SpellManager.HasSpell("Consecration") &&
                !Me.Mounted &&
                HasGlyph.Contains("41099") &&
                !CastingorGCDL() &&
                GetUnitConsecration() &&
                _unitConsecration != null &&
                _unitConsecration.IsValid &&
                GetSpellCooldown("Consecration").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   ////Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   LastClickRemoteLocation = DateTime.Now;
                                   CastSpell("Consecration", Me);
                                   ObjectManager.Update();
                                   while (LastClickRemoteLocation + TimeSpan.FromMilliseconds(300) < DateTime.Now &&
                                          Me.CurrentPendingCursorSpell == null)
                                   {
                                       Logging.Write("Waiting for Healing Sphere CurrentPendingCursorSpell");
                                   }

                                   SpellManager.ClickRemoteLocation(_unitConsecration.Location);
                               })
                );
        }

        #endregion

        #region CrusaderStrikeRet

        private Composite CrusaderStrikeRet()
        {
            return new Decorator(
                ret =>
                (THSettings.Instance.SCrusaderStrike ||
                 !SpellManager.HasSpell("Holy Insight")) &&
                !Me.Mounted &&
                Me.CurrentHolyPower < Me.MaxHolyPower &&
                !Me.HasAura("Divine Purposes") &&
                !Me.HasAura("Hand of Protection") &&
                Attackable(Me.CurrentTarget, 5) &&
                FacingOverride(Me.CurrentTarget) &&
                !CastingorGCDL() &&
                SpellManager.HasSpell("Crusader Strike") &&
                GetSpellCooldown("Crusader Strike").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   ////Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   SafelyFacingTarget(Me.CurrentTarget);
                                   CastSpell("Crusader Strike", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region CrusaderStrikeHoly

        private WoWUnit _unitCrusaderStrike;

        private WoWUnit GetUnitCrusaderStrikeHoly()
        {
            //using (StyxWoW.Memory.AcquireFrame())
            {
                _unitCrusaderStrike = null;
                _unitCrusaderStrike = (from unit in NearbyUnFriendlyUnits
                                       where unit.IsWithinMeleeRange
                                       where FacingOverride(unit)
                                       where Attackable(unit, 5)
                                       orderby unit.MaxHealth descending
                                       select unit).FirstOrDefault();

                return _unitCrusaderStrike;
            }
        }

        private Composite CrusaderStrikeHoly()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    THSettings.Instance.SCrusaderStrike &&
                    !Me.HasAura("Hand of Protection") &&
                    Me.Combat &&
                    GetUnitCrusaderStrikeHoly() != null &&
                    _unitCrusaderStrike.IsValid &&
                    Me.CurrentHolyPower < Me.MaxHolyPower &&
                    Me.IsFacing(_unitCrusaderStrike) &&
                    !CastingorGCDL() &&
                    GetSpellCooldown("Crusader Strike").TotalMilliseconds <= _myLatency,
                    new Action(delegate
                                   {
                                       SafelyFacingTarget(_unitCrusaderStrike);
                                       CastSpell("Crusader Strike", _unitCrusaderStrike);
                                       _unitCrusaderStrike = null;
                                   }))
                );
        }

        #endregion

        #region DevotionAura

        private Composite DevotionAura()
        {
            return new Decorator(
                ret =>
                Me.HealthPercent <= THSettings.Instance.SDevotionAura &&
                SpellManager.HasSpell("Devotion Aura") &&
                Me.Combat &&
                !Me.HasAura("Divine Shield") &&
                !Me.HasAura("Devotion Aura") &&
                !GCDL() && DebuffCC(Me) <= 0 &&
                GetSpellCooldown("Devotion Aura").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   if (Me.IsCasting && !IsHealing())
                                   {
                                       SpellManager.StopCasting();
                                   }
                                   CastSpell("Devotion Aura", Me);
                                   //Lua.DoString("RunMacroText(\"/s Used Devotion Aura - Immune to Silence and Interupt for 6 seconds.\")");
                                   return RunStatus.Failure;
                               }));
        }

        #endregion

        #region DivineLightBubble

        private Composite DivineLightBubble()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Divine Light") &&
                (Me.CurrentMap.IsBattleground ||
                 Me.CurrentMap.IsArena) &&
                (Me.HasAura("Divine Shield") ||
                 Me.HasAura("Devotion Aura") ||
                 Me.HasAura("Hand of Protection")) &&
                Healable(UnitHeal) &&
                !CastingorGCDL() &&
                !Me.IsMoving &&
                //(Me.Combat || UnitHeal.Combat) &&
                UnitHeal.HealthPercent <= THSettings.Instance.SDoNotHealAbove &&
                !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
                //!HoldonDivinePlea() &&
                Me.GetAuraById(54149) != null, //Infusion of Light
                new Action(delegate
                               {
                                   //Logging.Write("Bubble Heal - Divine Light");
                                   CastSpell("Divine Light", UnitHeal);
                                   UnitHeal = null;
                               }));
        }

        #endregion

        #region DivineProtectionMe

        private Composite DivineProtectionMe()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Divine Protection") &&
                !Me.Mounted &&
                Me.Combat &&
                !CastingorGCDL() &&
                Me.HealthPercent <= THSettings.Instance.SDivineProtection &&
                !Me.HasAura("Divine Shield") &&
                SpellManager.Spells["Divine Protection"].CooldownTimeLeft.TotalMilliseconds <= 0,
                new Action(delegate
                               {
                                   //Logging.Write("Casting Divine Protection SOON");
                                   //SpellManagerrrr.Cast(489);
                                   CastSpell("Divine Protection", Me);
                                   return RunStatus.Failure;
                               })
                );
        }

        #endregion

        #region DivineShieldMe

        private Composite DivineShieldMe()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Divine Shield") &&
                !Me.Mounted &&
                Me.Combat &&
                !CastingorGCDL() &&
                !Me.HasAura("Forbearance") &&
                !Me.HasAura("Alliance Flag") &&
                !Me.HasAura("Horde Flag") &&
                !Me.HasAura("Netherstorm Flag") &&
                !Me.HasAura("Orb of Power") &&
                !Me.HasAura("Ardent Defender") &&
                Me.HealthPercent < THSettings.Instance.SDivineShield &&
                GetSpellCooldown("Divine Shield").TotalMilliseconds <= _myLatency,
                new Action(delegate { CastSpell("Divine Shield", Me); }));
        }

        #endregion

        #region DivineStorm3HolyPower

        private Composite DivineStorm3HolyPower()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SDivineSStorm &&
                THSettings.Instance.SDivineStormUnit > 0 &&
                SpellManager.HasSpell("Divine Storm") &&
                !Me.Mounted &&
                !Me.HasAura("Hand of Protection") &&
                !Me.CurrentMap.IsArena &&
                !Me.CurrentMap.IsBattleground &&
                Attackable(Me.CurrentTarget, 5) &&
                (Me.CurrentHolyPower >= 3 ||
                 Me.HasAura("Divine Purpose")) &&
                !CastingorGCDL() &&
                CountEneyNeary(Me, 8) >= THSettings.Instance.SDivineStormUnit,
                new Action(delegate
                               {
                                   ////Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Divine Storm", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region DivineStorm5HolyPower

        private Composite DivineStorm5HolyPower()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SDivineSStorm &&
                THSettings.Instance.SDivineStormUnit > 0 &&
                SpellManager.HasSpell("Divine Storm") &&
                !Me.Mounted &&
                !Me.HasAura("Hand of Protection") &&
                !Me.CurrentMap.IsArena &&
                !Me.CurrentMap.IsBattleground &&
                Attackable(Me.CurrentTarget, 5) &&
                (Me.CurrentHolyPower == Me.MaxHolyPower ||
                 Me.HasAura("Divine Purpose") ||
                 Me.CurrentHolyPower >= 3 &&
                 Me.HasAura("Holy Avenger")) &&
                !CastingorGCDL() &&
                CountEneyNeary(Me, 10) >= THSettings.Instance.SDivineStormUnit,
                new Action(delegate
                               {
                                   ////Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   SafelyFacingTarget(Me.CurrentTarget);
                                   CastSpell("Divine Storm", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region DivineFavor

        private Composite DivineFavor()
        {
            return new Decorator(
                ret =>
                //_lastCastSpell != "Divine Favor" &&
                SpellManager.HasSpell("Divine Favor") &&
                Healable(UnitHeal) &&
                UnitHeal.Combat &&
                !UnitHeal.IsPet &&
                !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
                (UnitHeal.HealthPercent <= THSettings.Instance.SDivineFavor &&
                 LastBurstCalled < DateTime.Now ||
                 THSettings.Instance.SBurst) &&
                //IsMeorFocus(UnitHeal) && 
                !Me.HasAura("Divine Shield") &&
                GetSpellCooldown("Divine Favor").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   if (Me.IsCasting && !IsHealing())
                                   {
                                       SpellManager.StopCasting();
                                   }
                                   LastBurstCalled = DateTime.Now +
                                                     TimeSpan.FromMilliseconds(THSettings.Instance.BurstDelay);
                                   CastSpell("Divine Favor", Me);
                                   return RunStatus.Failure;
                               }));
        }

        #endregion

        #region DivineLight

        private Composite DivineLight()
        {
            return new Decorator(
                ret =>
                //Me.CurrentHolyPower < 3 &&
                //!Me.HasAura("Divine Purpose") &&
                SpellManager.HasSpell("Divine Light") &&
                Healable(UnitHeal) &&
                UnitHeal.HealthPercent <= THSettings.Instance.SDivineLight &&
                !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
                !CastingorGCDL() &&
                !Me.IsMoving &&
                //!IsOverrideModeOn &&
                (Me.Combat || UnitHeal.Combat) &&
                !HoldonDivinePlea() &&
                !Me.CurrentMap.IsArena &&
                !Me.CurrentMap.IsBattleground,
                new Action(delegate
                               {
                                   CastSpell("Divine Light", UnitHeal, "DivineLight");
                                   UnitHeal = null;
                               }));
        }

        #endregion

        #region DivineLight

        private Composite DivineLightProc()
        {
            return new Decorator(
                ret =>
                //Me.CurrentHolyPower < 3 &&
                //!Me.HasAura("Divine Purpose") &&
                SpellManager.HasSpell("Divine Light") &&
                Me.GetAuraById(54149) != null &&
                Healable(UnitHeal) &&
                UnitHeal.HealthPercent <= THSettings.Instance.SDivineLight &&
                !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
                !CastingorGCDL() &&
                !Me.IsMoving &&
                //!IsOverrideModeOn &&
                (Me.Combat || UnitHeal.Combat) &&
                !HoldonDivinePlea(),
                new Action(delegate
                               {
                                   CastSpell("Divine Light", UnitHeal, "DivineLightProc");
                                   UnitHeal = null;
                               }));
        }

        #endregion

        #region DivinePlea

        private Composite DivinePlea()
        {
            return new Decorator(
                ret =>
                !Me.Mounted &&
                //_lastCastSpell != "Divine Plea" &&
                (!Me.IsMoving || !HasGlyph.Contains("63223")) &&
                SpellManager.HasSpell("Divine Plea") &&
                !Me.HasAura("Holy Avenger") &&
                !Me.HasAura("Avenging Wrath") &&
                !Me.HasAura("Divine Favor") &&
                //Me.HasAura("Guardian of Ancient Kings") &&
                (Me.ManaPercent < THSettings.Instance.SDivinePlea ||
                 Me.ManaPercent < 70 &&
                 Me.CurrentMap.IsRaid &&
                 Me.HasAura("Hymn of Hope") &&
                 !HasGlyph.Contains("63223")) &&
                Healable(UnitHeal) &&
                (UnitHeal.HealthPercent > THSettings.Instance.SUrgentHeal ||
                 Me.ManaPercent < 10) &&
                !CastingorGCDL() &&
                GetSpellCooldown("Divine Plea").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //if (GetSpellCooldown("Divine Plea"))
                                   //{
                                   CastSpell("Divine Plea", Me);
                                   //}
                               }));
        }

        #endregion

        #region EmancipateMe

        private Composite EmancipateMe()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SEmancipate &&
                SpellManager.HasSpell("Emancipate") &&
                !Me.Mounted &&
                Attackable(Me.CurrentTarget, 40) &&
                Me.CurrentTarget.Distance > 6 &&
                !CastingorGCDL() &&
                !Me.HasAura("Hand of Freedom") &&
                Me.MovementInfo.RunSpeed < 4.5,
                new Action(delegate
                               {
                                   ////Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Emancipate", Me);
                               })
                );
        }

        #endregion

        #region EternalFlame

        private Composite EternalFlame()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Eternal Flame") &&
                Healable(UnitHeal) &&
                !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
                (Me.CurrentHolyPower >= 3 || Me.HasAura("Divine Purpose")) &&
                //MyAuraTimeLeft("Eternal Flame", UnitHeal) < 1500 && //Enable recast
                UnitHeal.HealthPercent <= THSettings.Instance.SWordofGlory &&
                !CastingorGCDL(),
                new Action(delegate
                               {
                                   CastSpell("Eternal Flame", UnitHeal);
                                   //_unitTankEternalFlame = null;
                               }));
        }

        #endregion

        #region EternalFlameBlanket

        private WoWUnit _unitEternalFlameBlanket;

        private bool GetUnitEternalFlameBlanket()
        {
            //using (StyxWoW.Memory.AcquireFrame())
            {
                _unitEternalFlameBlanket = null;

                //using (StyxWoW.Memory.AcquireFrame())
                {
                    _unitEternalFlameBlanket = (from unit in NearbyFriendlyPlayers
                                                orderby MyAuraTimeLeft("Eternal Flame", unit) descending
                                                orderby unit.HealthPercent ascending
                                                orderby unit.MaxHealth descending
                                                where MyAuraTimeLeft("Eternal Flame", unit) <= _myLatency
                                                where HealableValid(unit)
                                                select unit).FirstOrDefault();
                }

                return _unitEternalFlameBlanket != null;
            }
        }

        private Composite EternalFlameBlanket()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SEternalFlameBlanketHolyPower != 0 &&
                SpellManager.HasSpell("Eternal Flame") &&
                !Me.Mounted &&
                //Me.Combat &&
                (Me.CurrentHolyPower >= THSettings.Instance.SEternalFlameBlanketHolyPower ||
                 Me.HasAura("Divine Purpose")) &&
                GetUnitEternalFlameBlanket() &&
                _unitEternalFlameBlanket != null &&
                _unitEternalFlameBlanket.IsValid &&
                !CastingorGCDL(),
                new Action(delegate
                               {
                                   ////Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Eternal Flame", _unitEternalFlameBlanket);
                                   _unitEternalFlameBlanket = null;
                               })
                );
        }

        #endregion

        #region EternalFlameTank

        private Composite EternalFlameTank()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Eternal Flame") &&
                GetUnitTankEternalFlame() &&
                _unitTankEternalFlame != null &&
                _unitTankEternalFlame.IsValid &&
                (Me.CurrentHolyPower >= 3 || Me.HasAura("Divine Purpose")) &&
                !CastingorGCDL(),
                new Action(delegate
                               {
                                   CastSpell("Eternal Flame", _unitTankEternalFlame);
                                   //_unitTankEternalFlame = null;
                               }));
        }

        #endregion

        #region ExecutionSentenceHeal

        private Composite ExecutionSentenceHeal()
        {
            return new Decorator(
                ret =>
                //_lastCastSpell != "Execution Sentence" &&
                THSettings.Instance.SExecutionSentence &&
                THSettings.Instance.SUse90Defense != 0 &&
                SpellManager.HasSpell("Execution Sentence") &&
                !Me.Mounted &&
                Healable(UnitHeal) &&
                UnitHeal.Combat &&
                ((Me.CurrentMap.IsDungeon || Me.CurrentMap.IsRaid) && UnitHeal.HasAura("Vengeance") ||
                 UnitHeal == Me ||
                 UnitHeal.HasAura("Alliance Flag") ||
                 !UnitHeal.HasAura("Horde Flag") ||
                 !UnitHeal.HasAura("Netherstorm Flag") ||
                 !UnitHeal.HasAura("Orb of Power")) &&
                UnitHeal.HealthPercent < THSettings.Instance.SUse90Defense &&
                !CastingorGCDL() &&
                GetSpellCooldown("Execution Sentence").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   ////Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Execution Sentence", UnitHeal);
                                   UnitHeal = null;
                               })
                );
        }

        #endregion

        #region ExecutionSentenceRet

        private Composite ExecutionSentenceRet()
        {
            return new Decorator(
                ret =>
                //_lastCastSpell != "Execution Sentence" &&
                THSettings.Instance.SExecutionSentence &&
                THSettings.Instance.SUse90Attack != 0 &&
                SpellManager.HasSpell("Execution Sentence") &&
                !Me.Mounted &&
                Attackable(Me.CurrentTarget, 40) &&
                !Me.CurrentTarget.IsPet &&
                FacingOverride(UnitAttack) &&
                !InvulnerableMagic(Me.CurrentTarget) &&
                Me.CurrentTarget.InLineOfSpellSight &&
                Me.CurrentTarget.HealthPercent <= THSettings.Instance.SUse90Attack &
                Me.Specialization != WoWSpec.PaladinHoly &&
                (Me.CurrentTarget.CurrentHealth > Me.CurrentHealth*0.8 ||
                 Me.CurrentTarget.Name.Contains("Dummy") &&
                 !Me.IsInInstance) &&
                !CastingorGCDL() &&
                GetSpellCooldown("Execution Sentence").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   ////Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Execution Sentence", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region ExecutionSentenceAttackHoly

        private Composite ExecutionSentenceAttackHoly()
        {
            return new Decorator(
                ret =>
                //_lastCastSpell != "Execution Sentence" &&
                THSettings.Instance.SExecutionSentence &&
                THSettings.Instance.SUse90Attack != 0 &&
                SpellManager.HasSpell("Execution Sentence") &&
                !Me.Mounted &&
                Attackable(UnitAttack, 40) &&
                !UnitAttack.IsPet &&
                FacingOverride(UnitAttack) &&
                !Blacklist.Contains(UnitAttack.Guid, BlacklistFlags.All) &&
                UnitAttack.HealthPercent <= THSettings.Instance.SUse90Attack &
                !InvulnerableMagic(UnitAttack) &&
                (UnitAttack.CurrentHealth > Me.CurrentHealth*0.8 ||
                 UnitAttack.Name.Contains("Dummy")) &&
                !CastingorGCDL() &&
                GetSpellCooldown("Execution Sentence").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   ////Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   SafelyFacingTarget(UnitAttack);
                                   CastSpell("Execution Sentence", UnitAttack);
                               })
                );
        }

        #endregion

        #region Exorcism

        private Composite Exorcism()
        {
            return new Decorator(
                ret =>
                //_lastCastSpell != "Exorcism" &&
                THSettings.Instance.SExorcism &&
                SpellManager.HasSpell("Exorcism") &&
                !Me.Mounted &&
                Attackable(Me.CurrentTarget) &&
                FacingOverride(Me.CurrentTarget) &&
                !InvulnerableMagic(Me.CurrentTarget) &&
                (Me.CurrentTarget.Distance < 30 &&
                 !HasGlyph.Contains("122028") ||
                 Me.CurrentTarget.IsWithinMeleeRange) &&
                (Me.CurrentHolyPower < Me.MaxHolyPower || !Me.CurrentTarget.IsWithinMeleeRange) &&
                !CastingorGCDL() &&
                GetSpellCooldown("Exorcism").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   ////Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   SafelyFacingTarget(Me.CurrentTarget);
                                   CastSpell("Exorcism", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region FlashofLight

        private Composite FlashofLight()
        {
            return new Decorator(
                ret =>
                //Me.CurrentHolyPower < 3 &&
                //!Me.HasAura("Divine Purpose") &&
                SpellManager.HasSpell("Flash of Light") &&
                Healable(UnitHeal) &&
                UnitHeal.HealthPercent <= THSettings.Instance.SFlashofLight &&
                (Me.Combat || UnitHeal.Combat) &&
                !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
                !CastingorGCDL() &&
                !Me.IsMoving &&
                //!IsOverrideModeOn &&
                !HoldonDivinePlea(),
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "FlashofLight HealRotationCastComp");
                                   CastSpell("Flash of Light", UnitHeal);
                                   UnitHeal = null;
                               }));
        }

        #endregion

        #region FlashofLightBubble

        private Composite FlashofLightBubble()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Flash of Light") &&
                (Me.CurrentMap.IsBattleground ||
                 Me.CurrentMap.IsArena) &&
                (Me.HasAura("Divine Shield") ||
                 Me.HasAura("Devotion Aura") ||
                 Me.HasAura("Hand of Protection")) &&
                Healable(UnitHeal) &&
                !CastingorGCDL() &&
                !Me.IsMoving &&
                //!IsOverrideModeOn &&
                //(Me.Combat || UnitHeal.Combat) &&
                !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
                //!HoldonDivinePlea() &&
                UnitHeal.HealthPercent <= THSettings.Instance.SDoNotHealAbove,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "FlashofLight Bubble");
                                   //Logging.Write("Bubble Heal - Flash of Light");
                                   CastSpell("Flash of Light", UnitHeal);
                                   UnitHeal = null;
                               }));
        }

        #endregion

        #region FlashofLightFriendRet

        private Composite FlashofLightFriendRet()
        {
            return new Decorator(
                ret =>
                !Me.Mounted &&
                THSettings.Instance.SFlashofLightFriendRet != 0 &&
                SpellManager.HasSpell("Flash of Light") &&
                !Me.CurrentMap.IsDungeon &&
                !Me.CurrentMap.IsRaid &&
                !IsOverrideModeOn &&
                THSettings.Instance.SFlashofLightFriendRet != 0 &&
                !Me.IsMoving &&
                !IsOverrideModeOn &&
                Me.CurrentMana > Me.MaxMana*0.378 &&
                !CastingorGCDL() &&
                CountDPSTarget(Me) == 0 &&
                UnitHeal != null &&
                UnitHeal.IsValid &&
                UnitHeal.HealthPercent < THSettings.Instance.SFlashofLightFriendRet,
                new Action(delegate
                               {
                                   if (Me.IsMoving && Me.IsMoving)
                                   {
                                       Navigator.PlayerMover.MoveStop();
                                       WoWMovement.MoveStop();
                                   }
                                   //Logging.Write(LogLevel.Diagnostic, "FlashofLightFriendRet");
                                   DoNotMove = DateTime.Now + TimeSpan.FromSeconds(1);
                                   CastSpell("Flash of Light", UnitHeal);
                                   if (DoNotMove < DateTime.Now)
                                   {
                                       return RunStatus.Running;
                                   }
                                   return RunStatus.Success;
                               })
                );
        }

        #endregion

        #region FlashofLightMeRet

        private Composite FlashofLightMeRet()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SFlashofLightMeRet != 0 &&
                SpellManager.HasSpell("Flash of Light") &&
                !Me.Mounted &&
                !Me.CurrentMap.IsDungeon &&
                !Me.CurrentMap.IsRaid &&
                !Me.IsMoving &&
                !IsOverrideModeOn &&
                THSettings.Instance.SFlashofLightMeRet != 0 &&
                Me.CurrentMana > Me.MaxMana*0.4 &&
                !CastingorGCDL() &&
                CountDPSTarget(Me) == 0 &&
                Me.HealthPercent < THSettings.Instance.SFlashofLightMeRet,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "FlashofLightMeRet");
                                   DoNotMove = DateTime.Now + TimeSpan.FromSeconds(1);
                                   CastSpell("Flash of Light", Me);
                                   if (DoNotMove < DateTime.Now)
                                   {
                                       return RunStatus.Running;
                                   }
                                   return RunStatus.Success;
                               })
                );
        }

        #endregion

        #region FlashofLightMeTopUpRet

        private Composite FlashofLightMeTopUpRet()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Flash of Light") &&
                !IsOverrideModeOn &&
                !Me.Mounted &&
                !Me.Combat &&
                //!Me.IsMoving &&
                TreeRoot.Current.Name != "LazyRaider" &&
                Me.CurrentMana > Me.MaxMana*0.4 &&
                !CastingorGCDL() &&
                CountDPSTarget(Me) == 0 &&
                UnitHeal != null &&
                UnitHeal.IsValid &&
                !UnitHeal.Combat &&
                (UnitHeal.HealthPercent < THSettings.Instance.SDoNotHealAbove &&
                 (Me.CurrentMap.IsBattleground || Me.CurrentMap.IsArena)),
                new Action(delegate
                               {
                                   if (!IsOverrideModeOn && Me.IsMoving)
                                   {
                                       Navigator.PlayerMover.MoveStop();
                                       WoWMovement.MoveStop();
                                   }

                                   DoNotMove = DateTime.Now + TimeSpan.FromSeconds(1);
                                   //Logging.Write(LogLevel.Diagnostic, "FlashofLightMeTopUpRet");
                                   CastSpell("Flash of Light", UnitHeal);
                                   if (DoNotMove < DateTime.Now)
                                   {
                                       return RunStatus.Running;
                                   }
                                   return RunStatus.Success;
                               })
                );
        }

        #endregion

        #region FlashofLightSelflessHealer

        private Composite FlashofLightSelflessHealer()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SSelflessHealer != 0 &&
                !Me.Mounted &&
                !CastingorGCDL() &&
                Me.GetAuraById(114250) != null &&
                Me.GetAuraById(114250).StackCount > 2 &&
                UnitHeal != null &&
                UnitHeal.IsValid &&
                UnitHeal.HealthPercent < THSettings.Instance.SSelflessHealer,
                new Action(delegate
                               {
                                   ////Logging.Write(LogLevel.Diagnostic, "Selfless Healer Flash of Light");
                                   //SpellManager.Cast(85804, UnitHeal);
                                   //Logging.Write(LogLevel.Diagnostic, "FlashofLightSelflessHealerRet");
                                   CastSpell("Flash of Light", UnitHeal);
                                   UnitHeal = null;
                               })
                );
        }

        #endregion

        #region GuardianofAncientKings

        private Composite GuardianofAncientKings()
        {
            return new Decorator(
                ret =>
                //_lastCastSpell != "Divine Shield" &&
                Healable(UnitHeal) &&
                UnitHeal.Combat &&
                !UnitHeal.IsPet &&
                !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
                (UnitHeal.HealthPercent <= THSettings.Instance.SGuardianofAncientKingsHP &&
                 LastBurstCalled < DateTime.Now ||
                 THSettings.Instance.SBurst) &&
                //IsMeorFocus(UnitHeal) && 
                !Me.HasAura("Divine Shield") &&
                GetSpellCooldown("Guardian of Ancient Kings").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   if (Me.IsCasting && !IsHealing())
                                   {
                                       SpellManager.StopCasting();
                                   }
                                   LastBurstCalled = DateTime.Now +
                                                     TimeSpan.FromMilliseconds(THSettings.Instance.BurstDelay);
                                   CastSpell("Guardian of Ancient Kings", Me);
                                   return RunStatus.Failure;
                               }));
        }

        #endregion

        #region GuardianofAncientKingsAttack

        private Composite GuardianofAncientKingsAttack()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SGuardianofAncientKings &&
                THSettings.Instance.SBurst &&
                SpellManager.HasSpell("Guardian of Ancient Kings") &&
                !Me.Mounted &&
                Attackable(Me.CurrentTarget, 15) &&
                !Me.CurrentTarget.IsFlying &&
                !CastingorGCDL() &&
                GetSpellCooldown("Guardian of Ancient Kings").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Guardian of Ancient Kings", Me);
                               })
                );
        }

        #endregion

        #region GuardianofAncientKingsProtection

        private Composite GuardianofAncientKingsProtection()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SGuardianofAncientKings &&
                SpellManager.HasSpell("Guardian of Ancient Kings") &&
                !Me.Mounted &&
                Attackable(Me.CurrentTarget, 15) &&
                !Me.CurrentTarget.IsFlying &&
                !CastingorGCDL() &&
                Me.HealthPercent < THSettings.Instance.SGuardianofAncientKingsProt &&
                GetSpellCooldown("Guardian of Ancient Kings").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Guardian of Ancient Kings", Me);
                               })
                );
        }

        #endregion

        #region GetUnitAttackASAP

        public WoWUnit UnitAttackASAP;

        private bool GetUnitAttackASAP()
        {
            //using (StyxWoW.Memory.AcquireFrame())
            {
                if (!Me.CurrentMap.IsArena && !Me.CurrentMap.IsBattleground)
                {
                    return false;
                }

                UnitAttackASAP = null;

                //using (StyxWoW.Memory.AcquireFrame())
                {
                    UnitAttackASAP = (from unit in NearbyUnFriendlyPlayers
                                      where AttackableValid(unit)
                                      where UnitAuraTimeLeft("Dominate Mind", unit) > 0
                                      select unit).FirstOrDefault();
                }

                if (UnitAttackASAP == null)
                {
                    //using (StyxWoW.Memory.AcquireFrame())
                    {
                        UnitAttackASAP = (from unit in NearbyUnFriendlyUnits
                                          where AttackableValid(unit)
                                          where unit.IsPet && unit.IsCasting
                                          where
                                              (unit.CastingSpell.Name == "Mesmerize" ||
                                               unit.CastingSpell.Name == "Seduction")
                                          select unit).FirstOrDefault();
                    }
                }

                if (UnitAttackASAP == null)
                {
                    //using (StyxWoW.Memory.AcquireFrame())
                    {
                        UnitAttackASAP = (from unit in NearbyUnFriendlyPlayers
                                          where AttackableValid(unit)
                                          where unit.Class == WoWClass.Rogue || unit.Class == WoWClass.Druid
                                          where DotAll(unit) <= 0 && !unit.Combat
                                          select unit).FirstOrDefault();
                    }
                }

                //if (UnitAttackASAP == null)
                //{
                //    //using (StyxWoW.Memory.AcquireFrame())
                //    {
                //        UnitAttackASAP = (from unit in NearbyUnFriendlyPlayers
                //                          where AttackableValid(unit)
                //                          where unit.Class == WoWClass.Mage && unit.HasAura("Invisibility")
                //                          select unit).FirstOrDefault();
                //    }
                //}

                if (UnitAttackASAP == null)
                {
                    //using (StyxWoW.Memory.AcquireFrame())
                    {
                        UnitAttackASAP = (from unit in NearbyUnFriendlyUnits
                                          where AttackableValid(unit)
                                          where
                                              (unit.HasAura("Grounding Totem Effects") ||
                                               unit.Name == "Spirit Link Totem" ||
                                               unit.Name == "Grouding Totem" ||
                                               unit.Name == "Earthgrab Totem" ||
                                               unit.Name == "Earthbind Totem" ||
                                               unit.Name.Contains("Static Charge"))
                                          select unit).FirstOrDefault();
                    }
                }

                return UnitAttackASAP != null;
            }
        }

        #endregion

        #region GetPlayerHolyRadiance

        private WoWUnit _playerHolyRadiance;

        private double CountUnitHolyRadiance(WoWUnit unitCenter)
        {
            //using (StyxWoW.Memory.AcquireFrame())
            {
                return
                    NearbyFriendlyPlayers.Where(
                        unit =>
                        unitCenter.Location.Distance(unit.Location) <= 10 &&
                        unit.HealthPercent < THSettings.Instance.SHolyRadiance).Aggregate
                        <WoWPlayer, double>(0, (current, unit) => current + 1);
            }
        }

        private WoWUnit GetPlayerHolyRadiance()
        {
            //using (StyxWoW.Memory.AcquireFrame())
            {
                _playerHolyRadiance = null;
                if (THSettings.Instance.SHolyRadianceUnit != 0)
                {
                    _playerHolyRadiance = (from unit in NearbyFriendlyPlayers
                                           where CountUnitHolyRadiance(unit) >= THSettings.Instance.SHolyRadianceUnit
                                           where HealableValid(unit)
                                           orderby CountUnitHolyRadiance(unit) descending
                                           select unit).FirstOrDefault();
                }
                return _playerHolyRadiance;
            }
        }

        #endregion

        #region GetPlayerLightofDawn

        //private WoWUnit _playerLightofDawn;

        private double CountUnitLightofDawn(WoWUnit unitCenter)
        {
            return
                NearbyFriendlyPlayers.Where(
                    unit =>
                    unitCenter.Location.Distance(unit.Location) <= 30 &&
                    unit.HealthPercent < THSettings.Instance.SLightofDawn).Aggregate
                    <WoWPlayer, double>(0, (current, unit) => current + 1);
        }

        //private WoWUnit GetPlayerLightofDawn()
        //{
        //    PlayerLightofDawn = null;
        //    if (THSettings.Instance.SLightofDawnUnit > 0)
        //    {
        //        PlayerLightofDawn = (from unit in NearbyFriendlyPlayers
        //                             where GetMinDistance(unit) < 30
        //                             where CountUnitLightofDawn(unit) >= THSettings.Instance.SLightofDawnUnit
        //                             where HealableValid(unit)
        //                             orderby CountUnitLightofDawn(unit) descending
        //                             select unit).FirstOrDefault();
        //    }
        //    return PlayerLightofDawn;
        //}

        #endregion

        #region GetPlayerLightsHammer

        private WoWUnit _playerLightsHammer;

        private double CountUnitLightsHammer(WoWUnit unitCenter)
        {
            return
                NearbyFriendlyPlayers.Where(
                    unit =>
                    unitCenter.Location.Distance(unit.Location) <= 9 &&
                    unit.HealthPercent <= THSettings.Instance.SUse90Defense).Aggregate
                    <WoWPlayer, double>(0, (current, unit) => current + 1);
        }

        private bool GetPlayerLightsHammer()
        {
            _playerLightsHammer = null;

            //using (StyxWoW.Memory.AcquireFrame())
            {
                _playerLightsHammer = (from unit in NearbyFriendlyPlayers
                                       where THSettings.Instance.SUse90Defense != 0
                                       where !unit.IsMoving
                                       where unit.Combat
                                       where unit.GotTarget
                                       where !unit.CurrentTarget.IsMoving
                                       where GetMinDistance(unit) < 30
                                       where
                                           CountUnitLightsHammer(unit) >= 5 && Me.IsInMyRaid ||
                                           CountUnitLightsHammer(unit) >= 2 && Me.IsInMyParty
                                       where HealableValid(unit)
                                       orderby CountUnitLightsHammer(unit) descending
                                       select unit).FirstOrDefault();
                return _playerLightsHammer != null;
            }
        }

        #endregion

        #region GetUnitEternalFlame

        private WoWUnit _unitTankEternalFlame;

        private bool GetUnitTankEternalFlame()
        {
            _unitTankEternalFlame = null;
            //using (StyxWoW.Memory.AcquireFrame())
            {
                if (SpellManager.HasSpell("Eternal Flame") && (Me.CurrentMap.IsRaid || Me.CurrentMap.IsDungeon))
                {
                    //using (StyxWoW.Memory.AcquireFrame())
                    {
                        _unitTankEternalFlame = (from unit in NearbyFriendlyUnits
                                                 orderby unit.HealthPercent ascending
                                                 where unit.Combat
                                                 where unit.HasAura("Vengeance")
                                                 where IsEnemy(unit.CurrentTarget)
                                                 where unit.CurrentTarget.CurrentTarget == unit
                                                 where MyAuraTimeLeft("Eternal Flame", unit) <= 1500
                                                 where Healable(unit)
                                                 select unit).FirstOrDefault();
                    }
                }
                return _unitTankEternalFlame != null;
            }
        }

        #endregion

        #region GetUnitJudgment

        public WoWUnit UnitJudgment;

        private bool GetUnitJudgment()
        {
            //using (StyxWoW.Memory.AcquireFrame())
            {
                if (Me.Mounted ||
                    !SpellManager.HasSpell("Judgment"))
                {
                    return false;
                }

                UnitJudgment = null;
                if (SpellManager.HasSpell("Burden of Guilt"))
                {
                    //using (StyxWoW.Memory.AcquireFrame())
                    {
                        UnitJudgment = (from unit in NearbyUnFriendlyPlayers
                                        where Attackable(unit, 30 + _bonusJudgementRange)
                                        where !InvulnerableMagic(unit)
                                        orderby CountDebuffRootandSnare(unit) ascending
                                        orderby unit.Distance ascending
                                        select unit).FirstOrDefault();
                    }
                }
                if (UnitJudgment == null && SpellManager.HasSpell("Long Arm of the Law"))
                {
                    //using (StyxWoW.Memory.AcquireFrame())
                    {
                        UnitJudgment = (from unit in NearbyUnFriendlyUnits
                                        where Me.IsMoving
                                        where Me.HasAura("Hand of Freedom") || Me.MovementInfo.RunSpeed < 4
                                        where unit.IsPlayer || unit.IsPet
                                        where Attackable(unit, 30 + _bonusJudgementRange)
                                        where !InvulnerableMagic(unit)
                                        orderby unit.HealthPercent ascending
                                        select unit).FirstOrDefault();
                    }
                }
                //also support  [Selfless Healer]
                if (UnitJudgment == null && SpellManager.HasSpell("Selfless Healer"))
                {
                    //using (StyxWoW.Memory.AcquireFrame())
                    {
                        UnitJudgment = (from unit in NearbyUnFriendlyUnits
                                        where unit.GotTarget
                                        where Attackable(unit, 30 + _bonusJudgementRange)
                                        where !InvulnerableMagic(unit)
                                        orderby unit.HealthPercent ascending
                                        select unit).FirstOrDefault();
                    }
                }
                return UnitJudgment != null;
            }
        }

        #endregion

        #region GetUnitReckoning

        private WoWUnit _unitReckoning;

        private bool GetUnitReckoning()
        {
            _unitReckoning = null;
            //using (StyxWoW.Memory.AcquireFrame())
            {
                _unitReckoning = (from unit in NearbyUnFriendlyUnits
                                  orderby unit.Distance descending
                                  where unit.Combat
                                  where !unit.Name.Contains("Mine Cart")
                                  where
                                      SpellManager.HasSpell("Holy Insight") &&
                                      unit.IsPet &&
                                      unit.GotTarget &&
                                      unit.CurrentTarget != Me ||
                                      unit.IsPlayer && unit.Class == WoWClass.Rogue ||
                                      unit.IsPlayer && unit.Class == WoWClass.Druid && TalentSort(unit) == 1
                                  where GetMinDistance(unit) < 30
                                  where !Invulnerable(unit)
                                  where !InvulnerableMagic(unit)
                                  where AttackableValid(unit)
                                  select unit).FirstOrDefault();
            }
            return _unitReckoning != null;
        }

        private Composite ReckoningComp()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.STaunt &&
                SpellManager.HasSpell("Reckoning") &&
                _lastCastSpell != "Holy Light" &&
                _lastCastSpell != "Divine Light" &&
                _lastCastSpell != "Flash of Light" &&
                !CastingorGCDL() &&
                Me.Combat &&
                (Me.CurrentMap.IsArena || Me.CurrentMap.IsBattleground) &&
                GetUnitReckoning() &&
                _unitReckoning != null &&
                _unitReckoning.IsValid &&
                GetSpellCooldown("Reckoning").TotalMilliseconds <= _myLatency,
                new Action(
                    ret =>
                        {
                            CastSpell("Reckoning", _unitReckoning);
                            _unitReckoning = null;
                            return RunStatus.Failure;
                        })
                );
        }

        #endregion

        #region UnitHasSacredShield

        private WoWUnit _unitHasSacredShield;
        public double UnitSacredShieldTotalDebuff;
        public double UnitSacredShieldTotalTargetted;

        private bool GetUnitHasSacredShield()
        {
            _unitHasSacredShield = null;
            //using (StyxWoW.Memory.AcquireFrame())
            {
                if (SpellManager.HasSpell("Sacred Shield"))
                {
                    //using (StyxWoW.Memory.AcquireFrame())
                    {
                        _unitHasSacredShield = (from unit in FarFriendlyUnits
                                                where MyAuraTimeLeft(20925, unit) > 1500
                                                select unit).FirstOrDefault();
                    }
                }

                //if (UnitHasSacredShield != null)
                //{
                //UnitSacredShieldTotalDebuff = CountDebuff(UnitHasSacredShield);
                //UnitSacredShieldTotalTargetted = CountEneyTargettingUnit(UnitHasSacredShield, 40);
                //}
                return _unitHasSacredShield != null;
            }
        }

        #endregion

        #region UnitToSacredShield

        private WoWUnit _unitToSacredShield;

        private bool GetUnitToSacredShield()
        {
            _unitToSacredShield = null;

            //Sacred Shield Tank PvE
            if (_unitToSacredShield == null &&
                (Me.CurrentMap.IsRaid || Me.CurrentMap.IsDungeon))
            {
                //using (StyxWoW.Memory.AcquireFrame())
                {
                    _unitToSacredShield = (from unit in NearbyFriendlyUnits
                                           orderby unit.HealthPercent ascending
                                           where unit.HasAura("Vengeance")
                                           where IsEnemy(unit.CurrentTarget)
                                           //where unit.CurrentTarget.CurrentTarget == unit
                                           //where MyAuraTimeLeft(20925, unit) <= 1500
                                           where HealableValid(unit)
                                           select unit).FirstOrDefault();
                }
            }

            //Sacred Shield Lowest HP Unit, 
            if (_unitToSacredShield == null &&
                UnitHeal != null &&
                UnitHeal.Combat &&
                UnitHeal.HealthPercent <= THSettings.Instance.SDoNotHealAbove)
            {
                _unitToSacredShield = UnitHeal;
            }

            //Sacred Shield Flag or Orb Holder
            if (_unitToSacredShield == null && Me.CurrentMap.IsBattleground)
            {
                //using (StyxWoW.Memory.AcquireFrame())
                {
                    _unitToSacredShield = (from unit in NearbyFriendlyUnits
                                           orderby unit.HealthPercent ascending
                                           where !unit.Combat
                                           where !Me.Combat
                                           where unit.HasAura("Alliance Flag") ||
                                                 unit.HasAura("Horde Flag") ||
                                                 unit.HasAura("Netherstorm Flag") ||
                                                 unit.HasAura("Orb of Power")
                                           //where MyAuraTimeLeft(20925, unit) <= 1500
                                           where HealableValid(unit)
                                           select unit).FirstOrDefault();
                }
            }

            //Sacred Shield Most Focused Unit
            if (_unitToSacredShield == null)
            {
                //using (StyxWoW.Memory.AcquireFrame())
                {
                    _unitToSacredShield = (from unit in NearbyFriendlyUnits
                                           orderby CountEneyTargettingUnit(unit, 40) descending
                                           orderby CountDebuff(unit) descending
                                           where HealableValid(unit)
                                           select unit).FirstOrDefault();
                }
            }


            //Sacred Shield Me
            if (_unitToSacredShield == null &&
                (Me.CurrentMap.IsBattleground ||
                 Me.CurrentMap.IsArena) &&
                !GetUnitHasSacredShield())
            {
                _unitToSacredShield = Me;
            }

            //if (UnitToSacredShield != null)
            //{
            //    Logging.Write(LogLevel.Diagnostic, "UnitToSacredShield: " + UnitToSacredShield.Name);
            //}
            return _unitToSacredShield != null;
        }

        public DateTime LastSacredShield;

        private Composite SacredShieldHoly()
        {
            return new Decorator(
                ret =>
                //_lastCastSpell != "Sacred Shield" &&
                LastSacredShield + TimeSpan.FromSeconds(15) < DateTime.Now &&
                SpellManager.HasSpell("Sacred Shield") &&
                !Me.Mounted &&
                !CastingorGCDL() &&
                (Me.Combat || Me.IsInInstance) &&
                GetUnitToSacredShield() &&
                _unitToSacredShield != null &&
                _unitToSacredShield.IsValid &&
                MyAuraTimeLeft(20925, _unitToSacredShield) < 1500 &&
                GetSpellCooldown("Sacred Shield").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call UnitToSacredShield pls");
                                   CastSpell("Sacred Shield", _unitToSacredShield);
                                   _unitToSacredShield = null;
                                   LastSacredShield = DateTime.Now;
                               })
                );
        }

        #endregion

        #region HammerofJustice

        private Composite HammerofJustice()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SHammerofJustice != 0 &&
                _lastInterrupt < DateTime.Now &&
                UnitHeal != null &&
                UnitHeal.IsValid &&
                UnitHeal.HealthPercent > THSettings.Instance.SUrgentHeal &&
                (SpellManager.HasSpell("Hammer of Justice") &&
                 SpellManager.Spells["Hammer of Justice"].CooldownTimeLeft.TotalMilliseconds <= _myLatency &&
                 GetUnitInterrupt(10, _myLatency, THSettings.Instance.SHammerofJustice, false, false) ||
                 SpellManager.HasSpell("Fist of Justice") &&
                 SpellManager.Spells["Hammer of Justice"].CooldownTimeLeft.TotalMilliseconds <= _myLatency &&
                 GetUnitInterrupt(20, _myLatency, THSettings.Instance.SHammerofJustice, false, false)) &&
                _unitInterrupt != null && _unitInterrupt.IsValid,
                new Action(delegate
                               {
                                   if (Me.IsCasting)
                                   {
                                       SpellManager.StopCasting();
                                   }
                                   if (_unitInterrupt.IsCasting &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds >
                                       _myLatency + THSettings.Instance.SHammerofJustice)
                                   {
                                       return RunStatus.Running;
                                   }
                                   if (_unitInterrupt.IsCasting &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds <
                                       _myLatency + THSettings.Instance.SHammerofJustice &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds > _myLatency)
                                   {
                                       CastSpell("Hammer of Justice", _unitInterrupt);
                                       _lastInterrupt = DateTime.Now + TimeSpan.FromSeconds(1);
                                       return RunStatus.Success;
                                   }
                                   return RunStatus.Failure;
                               }));
        }

        #endregion

        #region HammerofJusticeBurstRet

        private Composite HammerofJusticeBurstRet()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SBurst &&
                SpellManager.HasSpell("Hammer of Justice") &&
                SpellManager.HasSpell("Guardian of Ancient Kings") &&
                Me.Mounted &&
                Attackable(Me.CurrentTarget, 10) &&
                Me.CurrentTarget.IsPlayer &&
                !CastingorGCDL() &&
                !InvulnerableMagic(Me.CurrentTarget) &&
                !InvulnerableStun(Me.CurrentTarget) &&
                Me.CurrentTarget.InLineOfSpellSight &&
                SpellManager.Spells["Guardian of Ancient Kings"].CooldownTimeLeft.TotalSeconds < 294 &&
                SpellManager.Spells["Guardian of Ancient Kings"].CooldownTimeLeft.TotalSeconds > 0 &&
                GetSpellCooldown("Hammer of Justice").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Hammer of Justice", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region HammeroftheRighteous

        private Composite HammeroftheRighteous()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SHammeroftheRighteous &&
                THSettings.Instance.SHammeroftheRighteousUnit > 0 &&
                SpellManager.HasSpell("Hammer of the Righteous") &&
                !Me.Mounted &&
                !Me.HasAura("Hand of Protection") &&
                !Me.CurrentMap.IsArena &&
                !Me.CurrentMap.IsBattleground &&
                Me.CurrentHolyPower < Me.MaxHolyPower &&
                Attackable(Me.CurrentTarget, 5) &&
                FacingOverride(Me.CurrentTarget) &&
                !CastingorGCDL() &&
                CountEneyNeary(Me, 10) >= THSettings.Instance.SHammeroftheRighteousUnit &&
                GetSpellCooldown("Hammer of the Righteous").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   SafelyFacingTarget(Me.CurrentTarget);
                                   CastSpell("Hammer of the Righteous", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region HammeroftheRighteousRetPvE4PlusUnit

        private Composite HammeroftheRighteousRetPvE4PlusUnit()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SHammeroftheRighteous &&
                THSettings.Instance.SHammeroftheRighteousUnit >= 4 &&
                SpellManager.HasSpell("Hammer of the Righteous") &&
                !Me.Mounted &&
                !Me.HasAura("Hand of Protection") &&
                !Me.CurrentMap.IsArena &&
                !Me.CurrentMap.IsBattleground &&
                Me.CurrentHolyPower < Me.MaxHolyPower &&
                Attackable(Me.CurrentTarget, 5) &&
                FacingOverride(Me.CurrentTarget) &&
                !CastingorGCDL() &&
                CountEneyNeary(Me, 10) >= THSettings.Instance.SHammeroftheRighteousUnit &&
                GetSpellCooldown("Hammer of the Righteous").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   SafelyFacingTarget(Me.CurrentTarget);
                                   CastSpell("Hammer of the Righteous", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region HammeroftheRighteousProtection

        private Composite HammeroftheRighteousProtection()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SHammeroftheRighteous &&
                THSettings.Instance.SHammeroftheRighteousUnit > 0 &&
                SpellManager.HasSpell("Hammer of the Righteous") &&
                !Me.Mounted &&
                !Me.HasAura("Hand of Protection") &&
                Me.CurrentHolyPower < Me.MaxHolyPower &&
                Attackable(Me.CurrentTarget, 5) &&
                FacingOverride(Me.CurrentTarget) &&
                !CastingorGCDL() &&
                (CountEneyNeary(Me, 10) >= THSettings.Instance.SUnittoStartAoE ||
                 !Me.CurrentTarget.HasAura("Weakened Blows")) &&
                GetSpellCooldown("Hammer of the Righteous").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   SafelyFacingTarget(Me.CurrentTarget);
                                   CastSpell("Hammer of the Righteous", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region HammeroftheRighteousRetArena

        private Composite HammeroftheRighteousRetArena()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SHammeroftheRighteous &&
                SpellManager.HasSpell("Hammer of the Righteous") &&
                !Me.Mounted &&
                Me.CurrentMap.IsArena &&
                !Me.HasAura("Hand of Protection") &&
                Attackable(Me.CurrentTarget, 5) &&
                Me.CurrentTarget.IsPlayer &&
                TalentSort(Me.CurrentTarget) <= 2 &&
                FacingOverride(Me.CurrentTarget) &&
                !CastingorGCDL() &&
                !Me.CurrentTarget.HasAura("Weakened Blows") &&
                GetSpellCooldown("Hammer of the Righteous").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   SafelyFacingTarget(Me.CurrentTarget);
                                   CastSpell("Hammer of the Righteous", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region HammerofWrathCurrentTarget

        private Composite HammerofWrathCurrentTarget()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Hammer of Wrath") &&
                _lastCastSpell != "Hammer of Wrath" &&
                (THSettings.Instance.SHammerofWrath ||
                 Me.Specialization != WoWSpec.PaladinHoly) &&
                !CastingorGCDL() &&
                !Me.Mounted &&
                !Me.HasAura("Hand of Protection") &&
                Attackable(Me.CurrentTarget) &&
                FacingOverride(Me.CurrentTarget) &&
                Me.CurrentTarget.Distance < 30 &&
                (Me.CurrentTarget.HealthPercent < 20 ||
                 Me.HasAura("Avenging Wrath") &&
                 Me.Specialization != WoWSpec.PaladinHoly) &&
                GetSpellCooldown("Hammer of Wrath").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   SafelyFacingTarget(Me.CurrentTarget);
                                   CastSpell("Hammer of Wrath", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region HammerofWrathUnitHammerofWrath

        private Composite HammerofWrathUnitHammerofWrath()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Hammer of Wrath") &&
                _lastCastSpell != "Hammer of Wrath" &&
                (THSettings.Instance.SHammerofWrath ||
                 Me.Specialization != WoWSpec.PaladinHoly) &&
                !Me.Mounted &&
                !Me.HasAura("Hand of Protection") &&
                !CastingorGCDL() &&
                GetUnitHammerofWrath() &&
                _unitHammerofWrath != null &&
                _unitHammerofWrath.IsValid &&
                FacingOverride(_unitHammerofWrath) &&
                GetSpellCooldown("Hammer of Wrath").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   SafelyFacingTarget(_unitHammerofWrath);
                                   CastSpell("Hammer of Wrath", _unitHammerofWrath);
                               })
                );
        }

        #endregion

        #region HandofFreedomMe

        private Composite HandofFreedomMe()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SHandofFreedomMyself &&
                SpellManager.HasSpell("Hand of Freedom") &&
                !Me.Mounted &&
                Attackable(Me.CurrentTarget) &&
                !Me.CurrentTarget.IsWithinMeleeRange &&
                !CastingorGCDL() &&
                Me.MovementInfo.RunSpeed < 4.5 &&
                !GetMyHandonUnit(Me) &&
                GetSpellCooldown("Hand of Freedom").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Hand of Freedom", Me);
                               })
                );
        }

        #endregion

        #region HandofFreedomMeHoly

        private Composite HandofFreedomMeHoly()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SHandofFreedomMyself &&
                SpellManager.HasSpell("Hand of Freedom") &&
                !Me.Mounted &&
                (Me.IsMoving || IsOverrideModeOn) &&
                //Attackable(Me.CurrentTarget) &&
                //!Me.CurrentTarget.IsWithinMeleeRange &&
                !CastingorGCDL() &&
                !Me.Stunned &&
                Me.MovementInfo.RunSpeed < 4.5 &&
                !GetMyHandonUnit(Me) &&
                GetSpellCooldown("Hand of Freedom").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Hand of Freedom", Me);
                               })
                );
        }

        #endregion

        #region HandofFreedomFriend

        private WoWUnit _unitHandofFreedom;

        private bool GetUnitHandofFreedom()
        {
            _unitHandofFreedom = null;

            if (_unitHandofFreedom == null && THSettings.Instance.SHandofFreedomMelee)
            {
                //using (StyxWoW.Memory.AcquireFrame())
                {
                    _unitHandofFreedom = (from unit in NearbyFriendlyPlayers
                                          where !Blacklist.Contains(unit.Guid, BlacklistFlags.All)
                                          where GetMinDistance(unit) < 30
                                          where unit.HealthPercent > 30
                                          where DebuffCC(unit) <= 0
                                          where TalentSort(unit) == 1
                                          where unit.Class != WoWClass.Paladin
                                          where unit.Class != WoWClass.Druid
                                          where unit.Class != WoWClass.Shaman
                                          where !GetMyHandonUnit(unit)
                                          where unit.GotTarget
                                          where IsEnemy(unit.CurrentTarget)
                                          //where unit.IsFacing(unit.CurrentTarget)
                                          where unit.Location.Distance(unit.CurrentTarget.Location) > 6
                                          where
                                              unit.MovementInfo.RunSpeed < 4 || unit.Rooted
                                          where HealableValid(unit)
                                          select unit).FirstOrDefault();
                }
            }

            if (_unitHandofFreedom == null && THSettings.Instance.SHandofFreedomHealer)
            {
                //using (StyxWoW.Memory.AcquireFrame())
                {
                    _unitHandofFreedom = (from unit in NearbyFriendlyPlayers
                                          where !Blacklist.Contains(unit.Guid, BlacklistFlags.All)
                                          where GetMinDistance(unit) < 30
                                          where unit.HealthPercent > 10
                                          where DebuffCC(unit) <= 0
                                          where TalentSort(unit) == 4
                                          where unit.Class != WoWClass.Paladin && unit.Class != WoWClass.Druid
                                          where !GetMyHandonUnit(unit)
                                          where CountMeleeDPSTarget(unit) > 0
                                          where
                                              unit.MovementInfo.RunSpeed < 4 || unit.Rooted
                                          where HealableValid(unit)
                                          select unit).FirstOrDefault();
                }
            }

            if (_unitHandofFreedom == null && THSettings.Instance.SHandofFreedomCaster)
            {
                //using (StyxWoW.Memory.AcquireFrame())
                {
                    _unitHandofFreedom = (from unit in NearbyFriendlyPlayers
                                          where !Blacklist.Contains(unit.Guid, BlacklistFlags.All)
                                          where GetMinDistance(unit) < 30
                                          where unit.HealthPercent > 30
                                          where DebuffCC(unit) <= 0
                                          where TalentSort(unit) > 1
                                          where TalentSort(unit) < 4
                                          where unit.Class != WoWClass.Druid
                                          where !GetMyHandonUnit(unit)
                                          where CountMeleeDPSTarget(unit) > 0
                                          where
                                              unit.MovementInfo.RunSpeed < 4.5 || unit.Rooted
                                          where HealableValid(unit)
                                          select unit).FirstOrDefault();
                }
            }


            return _unitHandofFreedom != null;
        }

        private Composite HandofFreedomFriend()
        {
            return new Decorator(
                ret =>
                (THSettings.Instance.SHandofFreedomMelee ||
                 THSettings.Instance.SHandofFreedomHealer ||
                 THSettings.Instance.SHandofFreedomCaster) &&
                SpellManager.HasSpell("Hand of Freedom") &&
                !Me.Mounted &&
                !CastingorGCDL() &&
                GetUnitHandofFreedom() && _unitHandofFreedom.IsValid && !GetMyHandonUnit(_unitHandofFreedom) &&
                GetSpellCooldown("Hand of Freedom").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Hand of Freedom", _unitHandofFreedom);
                               })
                );
        }

        #endregion

        #region HandofProtectionMe

        private Composite HandofProtectionMe()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Hand of Protection") &&
                !Me.Mounted &&
                Me.Combat &&
                !CastingorGCDL() &&
                !Me.HasAura("Forbearance") &&
                !Me.HasAura("Alliance Flag") &&
                !Me.HasAura("Horde Flag") &&
                !Me.HasAura("Netherstorm Flag") &&
                !Me.HasAura("Orb of Power") &&
                (Me.HealthPercent < THSettings.Instance.SHandofProtection) &&
                !GetMyHandonUnit(Me) &&
                CountMagicDPSTarget(Me) == 0 &&
                SpellManager.Spells["Divine Shield"].CooldownTimeLeft.TotalMilliseconds > _myLatency &&
                GetSpellCooldown("Hand of Protection").TotalMilliseconds <= _myLatency,
                new Action(delegate { CastSpell("Hand of Protection", Me); })
                );
        }

        #endregion

        #region HandofProtectionFriendRemoveCC

        private WoWPlayer _playerHandofProtectionFriendRemoveCc;

        private bool GetPlayerHandofProtectionFriendRemoveCC()
        {
            _playerHandofProtectionFriendRemoveCc = null;
            //using (StyxWoW.Memory.AcquireFrame())
            {
                if (THSettings.Instance.SHolyRadianceUnit != 0)
                {
                    _playerHandofProtectionFriendRemoveCc = (from unit in NearbyFriendlyPlayers
                                                             where HealableValid(unit)
                                                             where !Invulnerable(unit)
                                                             where !unit.HasAura("Forbearance")
                                                             where !unit.HasAura("Alliance Flag")
                                                             where !unit.HasAura("Horde Flag")
                                                             where !unit.HasAura("Netherstorm Flag")
                                                             where !unit.HasAura("Orb of Power")
                                                             where
                                                                 Me.CurrentMap.IsArena ||
                                                                 Me.CurrentMap.IsBattleground && TalentSort(unit) > 2
                                                             where
                                                                 unit.HasAura("Blind") &&
                                                                 unit.GetAuraByName("Blind").TimeLeft.TotalMilliseconds >
                                                                 3000 ||
                                                                 unit.HasAura("Intimidation Shout") &&
                                                                 unit.GetAuraByName("Intimidation Shout").TimeLeft.
                                                                      TotalMilliseconds > 3000
                                                             orderby TalentSort(unit) descending
                                                             select unit).FirstOrDefault();
                }
                return _playerHandofProtectionFriendRemoveCc != null;
            }
        }

        private Composite HandofProtectionFriendRemoveCC()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SHandofProtectionRemoveCC &&
                SpellManager.HasSpell("Hand of Protection") &&
                !CastingorGCDL() &&
                GetPlayerHandofProtectionFriendRemoveCC() &&
                GetSpellCooldown("Hand of Protection").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   CastSpell("Hand of Protection", _playerHandofProtectionFriendRemoveCc);
                                   _playerHandofProtectionFriendRemoveCc = null;
                               }));
        }

        #endregion

        #region HandofProtectionFriend

        private Composite HandofProtectionFriend()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Hand of Protection") &&
                //LastCastUnit != UnitHeal &&
                UnitHeal != null &&
                UnitHeal.IsValid &&
                !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
                UnitHeal.Distance < 30 &&
                UnitHeal.Combat &&
                UnitHeal.HealthPercent < THSettings.Instance.SHandofProtection &&
                UnitHeal.HealthPercent > 5 &&
                (UnitHeal != Me ||
                 UnitHeal == Me && SpellManager.Spells["Divine Shield"].CooldownTimeLeft.TotalSeconds > 2) &&
                !UnitHeal.HasAura("Forbearance") &&
                !Invulnerable(UnitHeal) &&
                !UnitHeal.HasAura("Alliance Flag") &&
                !UnitHeal.HasAura("Horde Flag") &&
                !UnitHeal.HasAura("Netherstorm Flag") &&
                !UnitHeal.HasAura("Orb of Power") &&
                (!UnitHeal.HasAura("Vengeance") ||
                 Me.CurrentMap.IsBattleground ||
                 Me.CurrentMap.IsArena) &&
                //!GetMyHandonUnit(UnitHeal) &&
                !CastingorGCDL() &&
                CountPhysicDPSTarget(UnitHeal) > 0 &&
                GetSpellCooldown("Hand of Protection").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   CastSpell("Hand of Protection", UnitHeal);
                                   UnitHeal = null;
                               }));
        }

        #endregion

        #region HandofSacrificeFriend

        private Composite HandofSacrificeFriend()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SHandofSacrifice != 0 &&
                SpellManager.HasSpell("Hand of Sacrifice") &&
                //LastCastUnit != UnitHeal &&
                Me.HealthPercent > THSettings.Instance.SPriorityHeal &&
                UnitHeal != null &&
                UnitHeal.IsValid &&
                !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
                UnitHeal.Combat &&
                UnitHeal.HealthPercent < THSettings.Instance.SHandofSacrifice &&
                UnitHeal.HealthPercent > 5 &&
                !Invulnerable(UnitHeal) &&
                !GetMyHandonUnit(UnitHeal)
                && !CastingorGCDL() &&
                CountDPSTarget(UnitHeal) > 0 &&
                GetSpellCooldown("Hand of Sacrifice").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   CastSpell("Hand of Sacrifice", UnitHeal);
                                   UnitHeal = null;
                               }))
                ;
        }

        #endregion

        #region HandofSalvation

        private Composite HandofSalvation()
        {
            return new Decorator(
                ret =>
                //_lastCastSpell != "Hand of Salvation" &&
                SpellManager.HasSpell("Hand of Salvation") &&
                !Me.Mounted &&
                Me.HasAura("Divine Plea") && !GetMyHandonUnit(Me) &&
                GetUnitDispellerAround() && (Me.CurrentMap.IsBattleground || Me.CurrentMap.IsArena) &&
                !CastingorGCDL() &&
                GetSpellCooldown("Hand of Salvation").TotalMilliseconds <= _myLatency,
                new Action(delegate { CastSpell("Hand of Salvation", Me); }));
        }

        #endregion

        #region HealRotation

        public DateTime LastBurstCalled;

        //private Composite HealRotation()
        //{
        //    return new PrioritySelector(
        //        new Decorator(
        //            ret =>
        //            //_lastCastSpell != "Holy Avenger" &&
        //            Healable(UnitHeal) &&
        //            UnitHeal.Combat &&
        //            !UnitHeal.IsPet &&
        //            !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
        //            (UnitHeal.HealthPercent <= THSettings.Instance.SHolyAvenger &&
        //             LastBurstCalled < DateTime.Now ||
        //             THSettings.Instance.SBurst) &&
        //            //IsMeorFocus(UnitHeal) &&
        //            !Me.HasAura("Divine Shield") &&
        //            SpellManager.HasSpell("Holy Avenger") &&
        //            GetSpellCooldown("Holy Avenger").TotalMilliseconds <= _myLatency,
        //            new Action(delegate
        //                {
        //                    if (Me.IsCasting && !IsHealing())
        //                    {
        //                        SpellManager.StopCasting();
        //                    }
        //                    LastBurstCalled = DateTime.Now +
        //                                      TimeSpan.FromMilliseconds(THSettings.Instance.BurstDelay);
        //                    CastSpell("Holy Avenger", Me);
        //                    return RunStatus.Failure;
        //                })),
        //        new Decorator(
        //            ret =>
        //            //_lastCastSpell != "Avenging Wrath" &&
        //            Healable(UnitHeal) &&
        //            UnitHeal.Combat &&
        //            !UnitHeal.IsPet &&
        //            !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
        //            (UnitHeal.HealthPercent <= THSettings.Instance.SAvengingWrathHP &&
        //             LastBurstCalled < DateTime.Now ||
        //             THSettings.Instance.SBurst) &&
        //            //IsMeorFocus(UnitHeal) && 
        //            !Me.HasAura("Divine Shield") &&
        //            GetSpellCooldown("Avenging Wrath").TotalMilliseconds <= _myLatency,
        //            new Action(delegate
        //                {
        //                    if (Me.IsCasting && !IsHealing())
        //                    {
        //                        SpellManager.StopCasting();
        //                    }
        //                    LastBurstCalled = DateTime.Now +
        //                                      TimeSpan.FromMilliseconds(THSettings.Instance.BurstDelay);
        //                    CastSpell("Avenging Wrath", Me);
        //                    return RunStatus.Failure;
        //                })),
        //        new Decorator(
        //            ret =>
        //            //_lastCastSpell != "Divine Favor" &&
        //            SpellManager.HasSpell("Divine Favor") &&
        //            Healable(UnitHeal) &&
        //            UnitHeal.Combat &&
        //            !UnitHeal.IsPet &&
        //            !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
        //            (UnitHeal.HealthPercent <= THSettings.Instance.SDivineFavor &&
        //             LastBurstCalled < DateTime.Now ||
        //             THSettings.Instance.SBurst) &&
        //            //IsMeorFocus(UnitHeal) && 
        //            !Me.HasAura("Divine Shield") &&
        //            GetSpellCooldown("Divine Favor").TotalMilliseconds <= _myLatency,
        //            new Action(delegate
        //                {
        //                    if (Me.IsCasting && !IsHealing())
        //                    {
        //                        SpellManager.StopCasting();
        //                    }
        //                    LastBurstCalled = DateTime.Now +
        //                                      TimeSpan.FromMilliseconds(THSettings.Instance.BurstDelay);
        //                    CastSpell("Divine Favor", Me);
        //                    return RunStatus.Failure;
        //                })),
        //        new Decorator(
        //            ret =>
        //            //_lastCastSpell != "Divine Shield" &&
        //            Healable(UnitHeal) &&
        //            UnitHeal.Combat &&
        //            !UnitHeal.IsPet &&
        //            !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
        //            (UnitHeal.HealthPercent <= THSettings.Instance.SGuardianofAncientKingsHP &&
        //             LastBurstCalled < DateTime.Now ||
        //             THSettings.Instance.SBurst) &&
        //            //IsMeorFocus(UnitHeal) && 
        //            !Me.HasAura("Divine Shield") &&
        //            GetSpellCooldown("Guardian of Ancient Kings").TotalMilliseconds <= _myLatency,
        //            new Action(delegate
        //                {
        //                    if (Me.IsCasting && !IsHealing())
        //                    {
        //                        SpellManager.StopCasting();
        //                    }
        //                    LastBurstCalled = DateTime.Now +
        //                                      TimeSpan.FromMilliseconds(THSettings.Instance.BurstDelay);
        //                    CastSpell("Guardian of Ancient Kings", Me);
        //                    return RunStatus.Failure;
        //                })),
        //        //Bubble Heal
        //        new Decorator(
        //            ret =>
        //            SpellManager.HasSpell("Divine Light") &&
        //            (Me.CurrentMap.IsBattleground ||
        //             Me.CurrentMap.IsArena) &&
        //            (Me.HasAura("Divine Shield") ||
        //             Me.HasAura("Devotion Aura") ||
        //             Me.HasAura("Hand of Protection")) &&
        //            Healable(UnitHeal) &&
        //            !CastingorGCDL() &&
        //            !Me.IsMoving &&
        //            //(Me.Combat || UnitHeal.Combat) &&
        //            UnitHeal.HealthPercent <= THSettings.Instance.SDoNotHealAbove &&
        //            !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
        //            //!HoldonDivinePlea() &&
        //            Me.GetAuraById(54149) != null, //Infusion of Light
        //            new Action(delegate
        //                {
        //                    Logging.Write("Bubble Heal - Divine Light");
        //                    CastSpell("Divine Light", UnitHeal);
        //                    UnitHeal = null;
        //                })),
        //        //Bubble Heal
        //        new Decorator(
        //            ret =>
        //            SpellManager.HasSpell("Flash of Light") &&
        //            (Me.CurrentMap.IsBattleground ||
        //             Me.CurrentMap.IsArena) &&
        //            (Me.HasAura("Divine Shield") ||
        //             Me.HasAura("Devotion Aura") ||
        //             Me.HasAura("Hand of Protection")) &&
        //            Healable(UnitHeal) &&
        //            !CastingorGCDL() &&
        //            !Me.IsMoving &&
        //            //!IsOverrideModeOn &&
        //            //(Me.Combat || UnitHeal.Combat) &&
        //            !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
        //            //!HoldonDivinePlea() &&
        //            UnitHeal.HealthPercent <= THSettings.Instance.SDoNotHealAbove,
        //            new Action(delegate
        //                {
        //                    //Logging.Write(LogLevel.Diagnostic, "FlashofLight Bubble");
        //                    Logging.Write("Bubble Heal - Flash of Light");
        //                    CastSpell("Flash of Light", UnitHeal);
        //                    UnitHeal = null;
        //                })),
        //        HolyPrismHeal(),
        //        LightHammerHeal(),
        //        ExecutionSentenceHeal(),
        //        new Decorator(
        //            ret =>
        //            SpellManager.HasSpell("Light of Dawn") &&
        //            THSettings.Instance.SLightofDawnUnit != 0 &&
        //            THSettings.Instance.SLightofDawn != 0 &&
        //            (Me.CurrentHolyPower >= 3 || Me.HasAura("Divine Purpose")) && !CastingorGCDL() &&
        //            CountUnitLightofDawn(Me) >= THSettings.Instance.SLightofDawnUnit,
        //            new Action(delegate { CastSpell("Light of Dawn", Me); })),
        //        new Decorator(
        //            ret =>
        //            SpellManager.HasSpell("Word of Glory") &&
        //            Healable(UnitHeal) &&
        //            UnitHeal.Combat &&
        //            !CastingorGCDL() &&
        //            !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
        //            UnitHeal.Combat &&
        //            !SpellManager.HasSpell("Eternal Flame") &&
        //            UnitHeal.HealthPercent <= THSettings.Instance.SWordofGlory &&
        //            (Me.CurrentHolyPower >= 3 ||
        //             Me.HasAura("Divine Purpose")),
        //            new Action(delegate
        //                {
        //                    //_unitBeaconSecond = null;
        //                    CastSpell("Word of Glory", UnitHeal);
        //                    UnitHeal = null;
        //                })),
        //        EternalFlameBlanket(),
        //        //Eternal Flame Tank
        //        new Decorator(
        //            ret =>
        //            SpellManager.HasSpell("Eternal Flame") &&
        //            GetUnitTankEternalFlame() &&
        //            _unitTankEternalFlame != null &&
        //            _unitTankEternalFlame.IsValid &&
        //            (Me.CurrentHolyPower >= 3 || Me.HasAura("Divine Purpose")) &&
        //            !CastingorGCDL(),
        //            new Action(delegate
        //                {
        //                    CastSpell("Eternal Flame", _unitTankEternalFlame);
        //                    //_unitTankEternalFlame = null;
        //                })),
        //        new Decorator(
        //            ret =>
        //            SpellManager.HasSpell("Eternal Flame") &&
        //            Healable(UnitHeal) &&
        //            !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
        //            SpellManager.HasSpell("Eternal Flame") &&
        //            (Me.CurrentHolyPower >= 3 || Me.HasAura("Divine Purpose")) &&
        //            //MyAuraTimeLeft("Eternal Flame", UnitHeal) < 1500 && //Enable recast
        //            UnitHeal.HealthPercent <= THSettings.Instance.SWordofGlory &&
        //            !CastingorGCDL(),
        //            new Action(delegate
        //                {
        //                    CastSpell("Eternal Flame", UnitHeal);
        //                    //_unitTankEternalFlame = null;
        //                })),
        //        FlashofLightSelflessHealer(),
        //        JudgmentSelflessHealerHoly(),
        //        new Decorator(
        //            ret =>
        //            //_lastCastSpell != "Holy Shock" &&
        //            !Me.Mounted &&
        //            !Me.HasAura("Drink") &&
        //            !Me.HasAura("Food") &&
        //            SpellManager.HasSpell("Holy Shock") &&
        //            (Me.CurrentMap.IsArena || Me.CurrentMap.IsBattleground || Me.Combat ||
        //             Me.ManaPercent >= THSettings.Instance.SManaforDPS &&
        //             (Me.CurrentMap.IsDungeon || Me.CurrentMap.IsRaid)) &&
        //            Healable(UnitHeal) &&
        //            !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
        //            (Me.CurrentHolyPower < 5 ||
        //             UnitHeal.HealthPercent <= THSettings.Instance.SDoNotHealAbove) &&
        //            !CastingorGCDL() &&
        //            SpellManager.Spells["Holy Shock"].CooldownTimeLeft.TotalMilliseconds <= 0,
        //            new Action(delegate
        //                {
        //                    //_unitBeaconSecond = null;
        //                    CastSpell("Holy Shock", UnitHeal);
        //                    UnitHeal = null;
        //                })),
        //        new Decorator(
        //            ret =>
        //            //_lastCastSpell != "Hand of Salvation" &&
        //            !Me.Mounted &&
        //            SpellManager.HasSpell("Hand of Salvation") &&
        //            Me.HasAura("Divine Plea") && !GetMyHandonUnit(Me) &&
        //            GetUnitDispellerAround() && (Me.CurrentMap.IsBattleground || Me.CurrentMap.IsArena) &&
        //            !CastingorGCDL() &&
        //            GetSpellCooldown("Hand of Salvation").TotalMilliseconds <= _myLatency,
        //            new Action(delegate { CastSpell("Hand of Salvation", Me); })),
        //        new Decorator(
        //            ret =>
        //            !Me.Mounted &&
        //            //_lastCastSpell != "Divine Plea" &&
        //            (!Me.IsMoving || HasGlyph.Contains("63223")) &&
        //            SpellManager.HasSpell("Divine Plea") &&
        //            !Me.HasAura("Holy Avenger") &&
        //            !Me.HasAura("Avenging Wrath") &&
        //            !Me.HasAura("Divine Favor") &&
        //            //Me.HasAura("Guardian of Ancient Kings") &&
        //            (Me.ManaPercent < THSettings.Instance.SDivinePlea ||
        //             Me.ManaPercent < 70 &&
        //             Me.CurrentMap.IsRaid &&
        //             Me.HasAura("Hymn of Hope") &&
        //             !HasGlyph.Contains("63223")) &&
        //            Healable(UnitHeal) &&
        //            (UnitHeal.HealthPercent > THSettings.Instance.SUrgentHeal ||
        //             Me.ManaPercent < 10) &&
        //            !CastingorGCDL() &&
        //            GetSpellCooldown("Divine Plea").TotalMilliseconds <= _myLatency,
        //            new Action(delegate
        //                {
        //                    //if (GetSpellCooldown("Divine Plea"))
        //                    //{
        //                    CastSpell("Divine Plea", Me);
        //                    //}
        //                })),
        //        SacredShieldHoly(),
        //        new Decorator(
        //            ret =>
        //            SpellManager.HasSpell("Holy Radiance") &&
        //            THSettings.Instance.SHolyRadianceUnit != 0 &&
        //            THSettings.Instance.SHolyRadiance != 0 &&
        //            !CastingorGCDL() && !Me.IsMoving &&
        //            GetPlayerHolyRadiance() != null &&
        //            _playerHolyRadiance != null &&
        //            _playerHolyRadiance.IsValid &&
        //            !HoldonDivinePlea() &&
        //            UnitHeal.HealthPercent > THSettings.Instance.SDivineLight,
        //            new Action(delegate
        //                {
        //                    CastSpell("Holy Radiance", _playerHolyRadiance);
        //                    _playerHolyRadiance = null;
        //                })),
        //        new Decorator(
        //            ret =>
        //            //Me.CurrentHolyPower < 3 &&
        //            //!Me.HasAura("Divine Purpose") &&
        //            SpellManager.HasSpell("Divine Light") &&
        //            Healable(UnitHeal) &&
        //            UnitHeal.HealthPercent <= THSettings.Instance.SDivineLight &&
        //            !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
        //            !CastingorGCDL() &&
        //            !Me.IsMoving &&
        //            //!IsOverrideModeOn &&
        //            (Me.Combat || UnitHeal.Combat) &&
        //            !HoldonDivinePlea() &&
        //            (Me.GetAuraById(54149) != null || Me.CurrentMap.IsDungeon ||
        //             Me.CurrentMap.IsRaid),
        //            new Action(delegate
        //                {
        //                    CastSpell("Divine Light", UnitHeal);
        //                    UnitHeal = null;
        //                })),
        //        new Decorator(
        //            ret =>
        //            //Me.CurrentHolyPower < 3 &&
        //            //!Me.HasAura("Divine Purpose") &&
        //            SpellManager.HasSpell("Flash of Light") &&
        //            Healable(UnitHeal) &&
        //            UnitHeal.HealthPercent <= THSettings.Instance.SFlashofLight &&
        //            (Me.Combat || UnitHeal.Combat) &&
        //            !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
        //            !CastingorGCDL() &&
        //            !Me.IsMoving &&
        //            //!IsOverrideModeOn &&
        //            !HoldonDivinePlea(),
        //            new Action(delegate
        //                {
        //                    //Logging.Write(LogLevel.Diagnostic, "FlashofLight HealRotationCastComp");
        //                    CastSpell("Flash of Light", UnitHeal);
        //                    UnitHeal = null;
        //                })),
        //        new Decorator(
        //            ret =>
        //            SpellManager.HasSpell("Holy Light") &&
        //            Healable(UnitHeal) &&
        //            UnitHeal.HealthPercent < THSettings.Instance.SDoNotHealAbove &&
        //            !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
        //            !CastingorGCDL() &&
        //            !Me.IsMoving &&
        //            UnitHeal.HealthPercent <= THSettings.Instance.SHolyLight &&
        //            (UnitHeal.HealthPercent >= THSettings.Instance.SDivineLight ||
        //             !UnitHeal.Combat && !Me.Combat) &&
        //            !HoldonDivinePlea(),
        //            new Action(delegate
        //                {
        //                    _unitBeaconSecond = null;
        //                    CastSpell("Holy Light", UnitHeal);
        //                    UnitHeal = null;
        //                }))
        //        );
        //}

        #endregion

        #region HoldonDivinePlea

        private bool HoldonDivinePlea()
        {
            if (!Me.HasAura("Divine Plea"))
            {
                return false;
            }

            if (Me.CurrentMap.IsBattleground || Me.CurrentMap.IsArena)
            {
                return false;
            }

            if (UnitHeal != null &&
                UnitHeal.IsValid &&
                UnitHeal.HealthPercent < THSettings.Instance.SUrgentHeal)
            {
                return false;
            }

            return true;
        }

        #endregion

        #region HolyAvenger

        private Composite HolyAvenger()
        {
            return new Decorator(
                ret =>
                //_lastCastSpell != "Holy Avenger" &&
                Healable(UnitHeal) &&
                UnitHeal.Combat &&
                !UnitHeal.IsPet &&
                !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
                (UnitHeal.HealthPercent <= THSettings.Instance.SHolyAvenger &&
                 LastBurstCalled < DateTime.Now ||
                 THSettings.Instance.SBurst) &&
                //IsMeorFocus(UnitHeal) &&
                !Me.HasAura("Divine Shield") &&
                SpellManager.HasSpell("Holy Avenger") &&
                GetSpellCooldown("Holy Avenger").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   if (Me.IsCasting && !IsHealing())
                                   {
                                       SpellManager.StopCasting();
                                   }
                                   LastBurstCalled = DateTime.Now +
                                                     TimeSpan.FromMilliseconds(THSettings.Instance.BurstDelay);
                                   CastSpell("Holy Avenger", Me);
                                   return RunStatus.Failure;
                               }));
        }

        #endregion

        #region HolyAvengerBurstRet

        private Composite HolyAvengerBurstRet()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SBurst &&
                SpellManager.HasSpell("Holy Avenger") &&
                SpellManager.HasSpell("Guardian of Ancient Kings") &&
                !Me.Mounted &&
                Attackable(Me.CurrentTarget, 15) &&
                !Me.CurrentTarget.IsFlying &&
                !CastingorGCDL() &&
                GetSpellCooldown("Guardian of Ancient Kings").TotalSeconds < 294 &&
                GetSpellCooldown("Guardian of Ancient Kings").TotalSeconds > 0 &&
                GetSpellCooldown("Holy Avenger").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Holy Avenger", Me);
                                   return RunStatus.Failure;
                               })
                );
        }

        #endregion

        #region HolyLight

        private Composite HolyLight()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Holy Light") &&
                Healable(UnitHeal) &&
                UnitHeal.HealthPercent < THSettings.Instance.SDoNotHealAbove &&
                //!Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
                !CastingorGCDL() &&
                !Me.IsMoving &&
                UnitHeal.HealthPercent <= THSettings.Instance.SHolyLight &&
                (UnitHeal.HealthPercent >= THSettings.Instance.SDivineLight ||
                 !UnitHeal.Combat && !Me.Combat) &&
                !HoldonDivinePlea(),
                new Action(delegate
                               {
                                   _unitBeaconSecond = null;
                                   CastSpell("Holy Light", UnitHeal);
                                   UnitHeal = null;
                               }));
        }

        #endregion

        #region HolyPrismHeal

        private Composite HolyPrismHeal()
        {
            return new Decorator(
                ret =>
                //_lastCastSpell != "Holy Prism" &&
                THSettings.Instance.SHolyPrism &&
                THSettings.Instance.SUse90Defense != 0 &&
                SpellManager.HasSpell("Holy Prism") &&
                !Me.Mounted &&
                Healable(UnitHeal) &&
                UnitHeal.Combat &&
                UnitHeal.HealthPercent <= THSettings.Instance.SUse90Defense &&
                !CastingorGCDL() &&
                GetSpellCooldown("Holy Prism").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Holy Prism", UnitHeal);
                                   UnitHeal = null;
                               })
                );
        }

        #endregion

        #region HolyPrismOffensiveRet

        private Composite HolyPrismRet()
        {
            return new Decorator(
                ret =>
                //_lastCastSpell != "Holy Prism" &&
                THSettings.Instance.SHolyPrism &&
                THSettings.Instance.SUse90Attack != 0 &&
                SpellManager.HasSpell("Holy Prism") &&
                !Me.Mounted &&
                Attackable(Me.CurrentTarget, 40) &&
                !Me.CurrentTarget.IsPet &&
                FacingOverride(Me.CurrentTarget) &&
                Me.Specialization != WoWSpec.PaladinHoly &&
                Me.CurrentTarget.HealthPercent <= THSettings.Instance.SUse90Attack &&
                !InvulnerableMagic(Me.CurrentTarget) &&
                !CastingorGCDL() &&
                GetSpellCooldown("Holy Prism").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   SafelyFacingTarget(Me.CurrentTarget);
                                   CastSpell("Holy Prism", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region HolyPrismAttackHoly

        private Composite HolyPrismAttackHoly()
        {
            return new Decorator(
                ret =>
                //_lastCastSpell != "Holy Prism" &&
                THSettings.Instance.SHolyPrism &&
                THSettings.Instance.SUse90Attack != 0 &&
                SpellManager.HasSpell("Holy Prism") &&
                !Me.Mounted &&
                Attackable(UnitAttack, 40) &&
                !UnitAttack.IsPet &&
                FacingOverride(UnitAttack) &&
                !Blacklist.Contains(UnitAttack.Guid, BlacklistFlags.All) &&
                (Me.CurrentMap.IsDungeon || UnitAttack.IsPlayer) &&
                UnitAttack.HealthPercent <= THSettings.Instance.SUse90Attack &&
                !InvulnerableMagic(UnitAttack) &&
                !CastingorGCDL() &&
                GetSpellCooldown("Holy Prism").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   SafelyFacingTarget(UnitAttack);
                                   CastSpell("Holy Prism", UnitAttack);
                               })
                );
        }

        #endregion

        #region HolyRadiance

        private Composite HolyRadiance()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Holy Radiance") &&
                THSettings.Instance.SHolyRadianceUnit != 0 &&
                THSettings.Instance.SHolyRadiance != 0 &&
                !CastingorGCDL() && !Me.IsMoving &&
                GetPlayerHolyRadiance() != null &&
                _playerHolyRadiance != null &&
                _playerHolyRadiance.IsValid &&
                !HoldonDivinePlea() &&
                UnitHeal.HealthPercent > THSettings.Instance.SDivineLight,
                new Action(delegate
                               {
                                   CastSpell("Holy Radiance", _playerHolyRadiance);
                                   _playerHolyRadiance = null;
                               }));
        }

        #endregion

        #region HolyShock

        private Composite HolyShock()
        {
            return new Decorator(
                ret =>
                //_lastCastSpell != "Holy Shock" &&
                SpellManager.HasSpell("Holy Shock") &&
                !Me.Mounted &&
                !Me.HasAura("Drink") &&
                !Me.HasAura("Food") &&
                (Me.CurrentMap.IsArena || Me.CurrentMap.IsBattleground || Me.Combat ||
                 Me.ManaPercent >= THSettings.Instance.SManaforDPS &&
                 (Me.CurrentMap.IsDungeon || Me.CurrentMap.IsRaid)) &&
                Healable(UnitHeal) &&
                !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
                (Me.CurrentHolyPower < 5 ||
                 UnitHeal.HealthPercent <= THSettings.Instance.SDoNotHealAbove) &&
                !CastingorGCDL() &&
                SpellManager.Spells["Holy Shock"].CooldownTimeLeft.TotalMilliseconds <= 0,
                new Action(delegate
                               {
                                   //_unitBeaconSecond = null;
                                   CastSpell("Holy Shock", UnitHeal);
                                   UnitHeal = null;
                               }));
        }

        #endregion

        #region HolyWrath

        private Composite HolyWrath()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SHolyWrath &&
                SpellManager.HasSpell("Holy Wrath") &&
                !Me.Mounted &&
                Attackable(Me.CurrentTarget, 5) &&
                FacingOverride(Me.CurrentTarget) &&
                !InvulnerableMagic(Me.CurrentTarget) &&
                !CastingorGCDL() &&
                GetSpellCooldown("Holy Wrath").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   SafelyFacingTarget(Me.CurrentTarget);
                                   CastSpell("Holy Wrath", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region InquisitionMe

        private Composite InquisitionMe()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Inquisition") &&
                !Me.Mounted &&
                Attackable(Me.CurrentTarget) &&
                !Me.CurrentTarget.IsFlying &&
                !CastingorGCDL() &&
                Me.CurrentTarget.Distance < 15 &&
                Me.CurrentTarget.InLineOfSpellSight &&
                (Me.CurrentHolyPower >= THSettings.Instance.SInquisitionHolyPower ||
                 Me.HasAura("Divine Purpose")) &&
                MyAuraTimeLeft("Inquisition", Me) <= 3000
                ,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Inquisition", Me);
                               }));
        }

        #endregion

        #region InquisitionMeTopUp

        private Composite InquisitionMeTopUp()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Inquisition") &&
                !Me.Mounted &&
                !CastingorGCDL() &&
                (Me.CurrentHolyPower >= THSettings.Instance.SInquisitionHolyPower ||
                 Me.HasAura("Divine Purpose")) &&
                MyAuraTimeLeft("Inquisition", Me) < 1000,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Inquisition", Me);
                               })
                );
        }

        #endregion

        #region Interrupt

        private static DateTime _lastInterrupt;

        private WoWUnit _unitInterrupt;

        private bool GetUnitInterrupt(int distance, double baseCastTime, double atCastTimeLeft, bool facingRequirement,
                                      bool interruptableRequirement)
        {
            _unitInterrupt = null;

            //using (StyxWoW.Memory.AcquireFrame())
            {
                if (Me.CurrentMap.IsBattleground || Me.CurrentMap.IsArena)
                {
                    _unitInterrupt = (from unit in NearbyUnFriendlyPlayers
                                      where !Blacklist.Contains(unit.Guid, BlacklistFlags.All)
                                      orderby unit.CurrentCastTimeLeft ascending
                                      where
                                          InterruptCastNoChannel(unit) > baseCastTime &&
                                          InterruptCastNoChannel(unit) < 1500 + atCastTimeLeft ||
                                          InterruptCastChannel(unit) > 0
                                      where
                                          unit.CanInterruptCurrentSpellCast ||
                                          !unit.CanInterruptCurrentSpellCast &&
                                          !interruptableRequirement
                                      where Attackable(unit, distance)
                                      where
                                          Me.IsFacing(unit) ||
                                          FacingOverride(unit) ||
                                          !Me.IsFacing(unit) && !facingRequirement
                                      where unit.InLineOfSpellSight
                                      select unit).FirstOrDefault();
                }
                    //PvE Search
                else if (!Me.IsInInstance || Me.CurrentMap.IsDungeon || Me.CurrentMap.IsRaid)
                {
                    _unitInterrupt = (from unit in NearbyUnFriendlyUnits
                                      where !Blacklist.Contains(unit.Guid, BlacklistFlags.All)
                                      where unit.IsCasting || unit.IsChanneling
                                      orderby unit.CurrentCastTimeLeft ascending
                                      where !unit.IsBoss
                                      where unit.Combat
                                      where
                                          unit.IsTargetingMeOrPet ||
                                          unit.IsTargetingMyPartyMember ||
                                          unit.IsTargetingMyRaidMember
                                      where
                                          unit.CanInterruptCurrentSpellCast ||
                                          !unit.CanInterruptCurrentSpellCast &&
                                          !interruptableRequirement
                                      where
                                          unit.CurrentCastTimeLeft.TotalMilliseconds > baseCastTime ||
                                          unit.IsChanneling
                                      where
                                          unit.CurrentCastTimeLeft.TotalMilliseconds <
                                          1500 + atCastTimeLeft || unit.IsChanneling
                                      where Attackable(unit, distance)
                                      where
                                          Me.IsFacing(unit) ||
                                          FacingOverride(unit) ||
                                          !Me.IsFacing(unit) && !facingRequirement
                                      select unit).FirstOrDefault();
                }
            }

            return _unitInterrupt != null;
        }

        #endregion

        #region Judgement Selfless Healer

        private WoWUnit _unitJudgmentSelflessHealerHoly;

        private bool GetUnitJudgmentSelflessHealerHoly()
        {
            _unitJudgmentSelflessHealerHoly = null;
            //using (StyxWoW.Memory.AcquireFrame())
            {
                _unitJudgmentSelflessHealerHoly = (from unit in NearbyUnFriendlyUnits
                                                   where
                                                       Me.GetAuraById(114250) == null ||
                                                       Me.GetAuraById(114250) != null &&
                                                       Me.GetAuraById(114250).StackCount < 3 ||
                                                       Me.GetAuraById(114250) != null &&
                                                       Me.GetAuraById(114250).TimeLeft.TotalMilliseconds < 6000
                                                   where Attackable(unit, 30 + _bonusJudgementRange)
                                                   where unit.Combat
                                                   where unit.GotTarget
                                                   where
                                                       unit.IsTargetingMeOrPet || unit.IsTargetingMyPartyMember ||
                                                       unit.IsTargetingMyRaidMember
                                                   where !InvulnerableMagic(unit)
                                                   orderby unit.HealthPercent ascending
                                                   select unit).FirstOrDefault();
            }
            return _unitJudgmentSelflessHealerHoly != null;
        }

        private Composite JudgmentSelflessHealerHoly()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    //THSettings.Instance.SJudgment &&
                    SpellManager.HasSpell("Selfless Healer") &&
                    SpellManager.HasSpell("Judgment") &&
                    !Me.Mounted &&
                    GetUnitJudgmentSelflessHealerHoly() &&
                    _unitJudgmentSelflessHealerHoly != null &&
                    _unitJudgmentSelflessHealerHoly.IsValid &&
                    GetSpellCooldown("Judgment").TotalMilliseconds <= _myLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                       CastSpell("Judgment", _unitJudgmentSelflessHealerHoly);
                                       _unitJudgmentSelflessHealerHoly = null;
                                   })));
        }

        #endregion

        #region JudgementRet

        private WoWUnit _lastJudgmentUnit;
        private WoWUnit _unitDoubleJeopardy;

        private bool GetUnitDoubleJeopardy()
        {
            _unitDoubleJeopardy = null;
            //using (StyxWoW.Memory.AcquireFrame())
            {
                if (Me.HasAura("Seal of Truth"))
                {
                    _unitDoubleJeopardy = (from unit in NearbyUnFriendlyUnits
                                           orderby MyAuraTimeLeft(31803, Me) ascending
                                           where unit != _lastJudgmentUnit
                                           where unit.Combat || unit.Name.Contains("Dummy") && Me.Combat
                                           where GetMinDistance(unit) < 30 + _bonusJudgementRange
                                           where
                                               unit.IsTargetingMeOrPet ||
                                               unit.IsTargetingMyPartyMember ||
                                               unit.IsTargetingMyRaidMember ||
                                               unit.Name.Contains("Dummy")
                                           where !Invulnerable(unit)
                                           where !InvulnerableMagic(unit)
                                           where unit.InLineOfSpellSight
                                           select unit).FirstOrDefault();
                }
                else
                {
                    _unitDoubleJeopardy = (from unit in NearbyUnFriendlyUnits
                                           orderby unit.HealthPercent descending
                                           where unit != _lastJudgmentUnit
                                           where unit.Combat || unit.Name.Contains("Dummy")
                                           where GetMinDistance(unit) < 30 + _bonusJudgementRange
                                           where
                                               unit.IsTargetingMeOrPet ||
                                               unit.IsTargetingMyPartyMember ||
                                               unit.IsTargetingMyRaidMember ||
                                               unit.Name.Contains("Dummy")
                                           where !Invulnerable(unit)
                                           where !InvulnerableMagic(unit)
                                           where unit.InLineOfSpellSight
                                           select unit).FirstOrDefault();
                }
            }

            if (_unitDoubleJeopardy == null &&
                Attackable(Me.CurrentTarget, 30 + _bonusJudgementRange) &&
                !InvulnerableMagic(Me.CurrentTarget))
            {
                _unitDoubleJeopardy = Me.CurrentTarget;
            }
            return _unitDoubleJeopardy != null;
        }

        private Composite JudgementRet()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    SpellManager.HasSpell("Judgment") &&
                    (THSettings.Instance.SJudgment ||
                     !SpellManager.HasSpell("Holy Insight")) &&
                    (!HasGlyph.Contains("54922") || //Glyph of Double Jeopardy - 
                     Me.CurrentMap.IsBattleground ||
                     Me.CurrentMap.IsArena) &&
                    !Me.Mounted &&
                    Attackable(Me.CurrentTarget, 30 + _bonusJudgementRange) &&
                    !InvulnerableMagic(Me.CurrentTarget) &&
                    !CastingorGCDL() &&
                    (Me.CurrentHolyPower < Me.MaxHolyPower || !Me.CurrentTarget.IsWithinMeleeRange) &&
                    GetSpellCooldown("Judgment").TotalMilliseconds <= _myLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                       CastSpell("Judgment", Me.CurrentTarget);
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SJudgment &&
                    SpellManager.HasSpell("Judgment") &&
                    HasGlyph.Contains("54922") && //Glyph of Double Jeopardy - 
                    //Me.GetAuraById(121027) != null && //Glyph of Double Jeopardy
                    !Me.Mounted &&
                    !CastingorGCDL() &&
                    (Me.CurrentHolyPower < Me.MaxHolyPower) &&
                    GetUnitDoubleJeopardy() &&
                    _unitDoubleJeopardy != null &&
                    _unitDoubleJeopardy.IsValid &&
                    GetSpellCooldown("Judgment").TotalMilliseconds <= _myLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                       CastSpell("Judgment", _unitDoubleJeopardy);
                                       _lastJudgmentUnit = _unitDoubleJeopardy;
                                   })
                    ));
        }

        #endregion

        #region JudgementRangeRetPvP

        private Composite JudgementRangeRetPvP()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SJudgment &&
                SpellManager.HasSpell("Judgment") &&
                (Me.CurrentMap.IsArena ||
                 Me.CurrentMap.IsBattleground) &&
                !Me.Mounted &&
                !Me.HasAura("Hand of Protection") &&
                Attackable(Me.CurrentTarget, 30 + _bonusJudgementRange) &&
                !CastingorGCDL() &&
                (SpellManager.HasSpell("Long Arm of the Law") &&
                 GetMaxDistance(Me.CurrentTarget) > 8 ||
                 SpellManager.HasSpell("Burden of Guilt") &&
                 Me.CurrentTarget.MovementInfo.RunSpeed > 4) &&
                GetSpellCooldown("Judgment").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Judgment", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region JudgementRangeRetPvE

        private Composite JudgementRangeRetPvE()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SJudgment &&
                SpellManager.HasSpell("Judgment") &&
                (Me.CurrentMap.IsDungeon ||
                 Me.CurrentMap.IsRaid) &&
                !Me.Mounted &&
                !Me.HasAura("Hand of Protection") &&
                Attackable(Me.CurrentTarget, 30 + _bonusJudgementRange) &&
                !CastingorGCDL() &&
                (SpellManager.HasSpell("Long Arm of the Law") &&
                 GetMaxDistance(Me.CurrentTarget) > 8) &&
                GetSpellCooldown("Judgment").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Judgment", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region LayonHandsMe

        private Composite LayonHandsMe()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SLayonHands != 0 &&
                SpellManager.HasSpell("Lay on Hands") &&
                !Me.Mounted &&
                Me.Combat &&
                !CastingorGCDL() &&
                !Me.CurrentMap.IsArena &&
                !Me.IsFFAPvPFlagged &&
                !Me.HasAura("Forbearance") &&
                Me.HealthPercent < THSettings.Instance.SLayonHands &&
                GetSpellCooldown("Lay on Hands").TotalMilliseconds <= _myLatency &&
                //SpellManager.HasSpell("Divine Shield") && Don't Care because Lay On Hands at 16 and Divine Shield at 20
                SpellManager.Spells["Divine Shield"].CooldownTimeLeft.TotalMilliseconds > _myLatency,
                new Action(delegate
                               {
                                   CastSpell("Lay on Hands", Me);
                                   return RunStatus.Failure;
                               })
                );
        }

        #endregion

        #region LayonHandsFriend

        private Composite LayonHandsFriend()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SLayonHands != 0 &&
                SpellManager.HasSpell("Lay on Hands") &&
                !Me.Mounted &&
                Me.Combat &&
                !Me.CurrentMap.IsArena &&
                !Me.IsFFAPvPFlagged &&
                !CastingorGCDL() &&
                UnitHeal != null &&
                UnitHeal.IsValid &&
                UnitHeal.HealthPercent < THSettings.Instance.SLayonHands &&
                !UnitHeal.HasAura("Forbearance") &&
                (UnitHeal.HasAura("Alliance Flag") ||
                 UnitHeal.HasAura("Horde Flag") ||
                 UnitHeal.HasAura("Netherstorm Flag") ||
                 UnitHeal.HasAura("Orb of Power") ||
                 Me.CurrentTarget == UnitHeal ||
                 Me.FocusedUnit == UnitHeal ||
                 Me.CurrentMap.IsRaid ||
                 Me.CurrentMap.IsDungeon) &&
                GetSpellCooldown("Lay on Hands").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   CastSpell("Lay on Hands", UnitHeal);
                                   return RunStatus.Failure;
                               })
                );
        }

        #endregion

        #region LightHammerHeal

        public DateTime LastClickRemoteLocation;

        private Composite LightHammerHeal()
        {
            return new Decorator(
                ret =>
                //_lastCastSpell != "Light's Hammer" &&
                THSettings.Instance.SLightsHammer &&
                THSettings.Instance.SUse90Defense != 0 &&
                SpellManager.HasSpell("Light's Hammer") &&
                !Me.Mounted &&
                Me.Combat &&
                GetPlayerLightsHammer() &&
                _playerLightsHammer != null &&
                _playerLightsHammer.IsValid &&
                !CastingorGCDL() &&
                GetSpellCooldown("Light's Hammer").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   LastClickRemoteLocation = DateTime.Now;
                                   CastSpell("Light's Hammer", Me);
                                   while (LastClickRemoteLocation + TimeSpan.FromMilliseconds(300) < DateTime.Now &&
                                          Me.CurrentPendingCursorSpell == null)
                                   {
                                       Logging.Write("Waiting for Healing Sphere CurrentPendingCursorSpell");
                                   }

                                   SpellManager.ClickRemoteLocation(_playerLightsHammer.Location);
                               })
                );
        }

        #endregion

        #region LightHammerRet

        private Composite LightHammerRet()
        {
            return new Decorator(
                ret =>
                //_lastCastSpell != "Light's Hammer" &&
                THSettings.Instance.SLightsHammer &&
                THSettings.Instance.SUse90Attack != 0 &&
                SpellManager.HasSpell("Light's Hammer") &&
                !Me.Mounted &&
                Attackable(Me.CurrentTarget, 40) &&
                !Me.CurrentTarget.IsPet &&
                Me.CurrentTarget.Distance < 40 &&
                !InvulnerableMagic(Me.CurrentTarget) &&
                !Me.CurrentTarget.IsFlying &&
                Me.Specialization != WoWSpec.PaladinHoly &&
                Me.CurrentTarget.HealthPercent <= THSettings.Instance.SUse90Attack &&
                Me.CurrentTarget.Combat && Me.Combat &&
                (Me.CurrentTarget.CurrentHealth > Me.CurrentHealth*0.8 ||
                 Me.CurrentTarget.Name.Contains("Dummy") &&
                 !Me.IsInInstance) &&
                !CastingorGCDL() &&
                GetSpellCooldown("Light's Hammer").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   LastClickRemoteLocation = DateTime.Now;
                                   SafelyFacingTarget(Me.CurrentTarget);
                                   CastSpell("Light's Hammer", Me);
                                   while (LastClickRemoteLocation + TimeSpan.FromMilliseconds(300) < DateTime.Now &&
                                          Me.CurrentPendingCursorSpell == null)
                                   {
                                       Logging.Write("Waiting for Healing Sphere CurrentPendingCursorSpell");
                                   }
                                   SpellManager.ClickRemoteLocation(Me.CurrentTarget.Location);
                               })
                );
        }

        #endregion

        #region LightofDawn

        private Composite LightofDawn()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Light of Dawn") &&
                THSettings.Instance.SLightofDawnUnit != 0 &&
                THSettings.Instance.SLightofDawn != 0 &&
                (Me.CurrentHolyPower >= 3 || Me.HasAura("Divine Purpose")) && !CastingorGCDL() &&
                CountUnitLightofDawn(Me) >= THSettings.Instance.SLightofDawnUnit,
                new Action(delegate { CastSpell("Light of Dawn", Me); }));
        }

        #endregion

        #region Rebuke

        private Composite Rebuke()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SRebuke != 0 &&
                SpellManager.HasSpell("Rebuke") &&
                _lastInterrupt < DateTime.Now &&
                SpellManager.Spells["Rebuke"].CooldownTimeLeft.TotalMilliseconds <= _myLatency &&
                GetUnitInterrupt(5, _myLatency, THSettings.Instance.SRebuke, true, true) &&
                _unitInterrupt != null && _unitInterrupt.IsValid,
                new Action(delegate
                               {
                                   if (!Me.IsSafelyFacing(_unitInterrupt))
                                   {
                                       _unitInterrupt.Face();
                                   }
                                   if (Me.IsCasting)
                                   {
                                       SpellManager.StopCasting();
                                   }
                                   if (_unitInterrupt.IsCasting &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds >
                                       _myLatency + THSettings.Instance.SRebuke)
                                   {
                                       return RunStatus.Running;
                                   }
                                   if (_unitInterrupt.IsCasting &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds <
                                       _myLatency + THSettings.Instance.SRebuke &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds > _myLatency)
                                   {
                                       CastSpell("Rebuke", _unitInterrupt);
                                       _lastInterrupt = DateTime.Now + TimeSpan.FromSeconds(1);
                                       return RunStatus.Failure;
                                   }
                                   return RunStatus.Failure;
                               }));
        }

        #endregion

        #region ReckoningCompProtection

        private WoWUnit _unitReckoningProtection;

        private bool GetUnitReckoningProtection()
        {
            _unitReckoningProtection = null;
            //using (StyxWoW.Memory.AcquireFrame())
            {
                _unitReckoningProtection = (from unit in NearbyUnFriendlyUnits
                                            where Me.Combat
                                            where Me.CurrentMap.IsDungeon || Me.CurrentMap.IsRaid
                                            where unit.Combat && !unit.Fleeing
                                            where unit.ThreatInfo.RawPercent < 100
                                            where (unit.IsTargetingMyPartyMember || unit.IsTargetingMyRaidMember)
                                            where !unit.IsTargetingMeOrPet
                                            //Make sure dont taunt off another tank
                                            where !unit.CurrentTarget.HasAura("Vengeance")
                                            where GetMinDistance(unit) < 30
                                            where unit.InLineOfSpellSight
                                            select unit).FirstOrDefault();
                return _unitReckoningProtection != null;
            }
        }

        private Composite ReckoningCompProtection()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.STaunt &&
                SpellManager.HasSpell("Reckoning") &&
                !Me.IsFlying &&
                GetUnitReckoningProtection() && _unitReckoningProtection.IsValid &&
                GetSpellCooldown("Reckoning").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   CastSpell("Reckoning", _unitReckoningProtection);
                                   return RunStatus.Failure;
                               })
                );
        }

        #endregion

        #region Repentance

        private WoWUnit _unitFriendlyTargeting;
        private WoWUnit _unitRepentance;

        private bool IsTargetedByOurUnit(WoWUnit u)
        {
            _unitFriendlyTargeting = null;
            //using (StyxWoW.Memory.AcquireFrame())
            {
                _unitFriendlyTargeting = (from unit in FarFriendlyUnits
                                          where unit != Me
                                          where unit.CurrentTarget == u
                                          //where TalentSort(unit) > 0
                                          //where unit.Location.Distance(u.Location) < 40//Disable for speed
                                          select unit).FirstOrDefault();
            }

            if (_unitFriendlyTargeting != null)
            {
                return true;
            }
            return false;
        }

        //private bool IsTargetedByOurDPS(WoWUnit u)
        //{
        //    _unitFriendlyTargeting = null;
        //    //using (StyxWoW.Memory.AcquireFrame())
        //    {
        //        _unitFriendlyTargeting = (from unit in NearbyFriendlyPlayers
        //                                 where unit.CurrentTarget == u
        //                                 where TalentSort(unit) <= 3
        //                                 //where TalentSort(unit) > 0
        //                                 //where unit.Location.Distance(u.Location) < 40//Disable for speed
        //                                 select unit).FirstOrDefault();
        //    }

        //    if (_unitFriendlyTargeting != null)
        //    {
        //        return true;
        //    }
        //    return false;
        //}

        private bool GetUnitRepentance()
        {
            if (!THSettings.Instance.SRepentanceCC)
            {
                return false;
            }

            _unitRepentance = null;
            if (SpellManager.HasSpell("Repentance"))
            {
                //using (StyxWoW.Memory.AcquireFrame())
                {
                    _unitRepentance = (from unit in NearbyUnFriendlyPlayers
                                       where !Blacklist.Contains(unit.Guid, BlacklistFlags.All)
                                       orderby TalentSortSimple(unit) descending
                                       orderby unit.HealthPercent descending
                                       where GetMinDistance(unit) < 30
                                       where !Invulnerable(unit)
                                       where !InvulnerableMagic(unit)
                                       where unit.InLineOfSpellSight
                                       where unit.HealthPercent > 50
                                       where DotAll(unit) < 1000
                                       where !unit.HasAura("Berserker Rage")
                                       where !unit.HasAura("Bear Form")
                                       where !unit.HasAura("Cat Form")
                                       where !unit.HasAura("Aquatic Form")
                                       where !unit.HasAura("Travel Form")
                                       where !unit.HasAura("Flight Form")
                                       where !unit.HasAura("Swift Flight Form  ")
                                       where !unit.HasAura("Ghost Wolf")
                                       where !unit.HasAura("Lichborne")
                                       where DebuffCC(unit) < 1500
                                       where !IsTargetedByOurUnit(unit) || unit.Mounted && unit.IsMoving
                                       select unit).FirstOrDefault();
                }
            }

            return _unitRepentance != null;
        }

        private Composite RepentanceComp()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    THSettings.Instance.SRepentanceCC &&
                    THSettings.Instance.SRepentance != 0 &&
                    SpellManager.HasSpell("Repentance") &&
                    Me.HealthPercent > THSettings.Instance.SPriorityHeal &&
                    (Me.CurrentMap.IsArena || Me.CurrentMap.IsBattleground) &&
                    !Me.IsMoving && !CastingorGCDL() &&
                    GetUnitRepentance() && _unitRepentance.IsValid &&
                    GetSpellCooldown("Repentance").TotalMilliseconds <= _myLatency,
                    new Action(delegate
                                   {
                                       CastSpell("Repentance", _unitRepentance);
                                       Blacklist.Add(_unitRepentance.Guid, BlacklistFlags.All, TimeSpan.FromSeconds(1));
                                   }))
                );
        }

        #endregion

        #region Righteous Fury

        private Composite RighteousFury()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    THSettings.Instance.SRighteousFury &&
                    SpellManager.HasSpell("Righteous Fury") &&
                    !Me.HasAura("Righteous Fury") &&
                    (SpellManager.HasSpell("Avenger's Shield") &&
                     (Me.CurrentMap.IsDungeon ||
                      Me.CurrentMap.IsRaid) ||
                     Me.CurrentMap.IsArena ||
                     Me.CurrentMap.IsBattleground) &&
                    !CastingorGCDL(),
                    new Action(delegate { CastSpell("Righteous Fury", Me); })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SRighteousFury &&
                    Me.HasAura("Righteous Fury") &&
                    !SpellManager.HasSpell("Avenger's Shield") &&
                    !Me.CurrentMap.IsArena &&
                    !Me.CurrentMap.IsBattleground,
                    new Action(delegate
                                   {
                                       Lua.DoString("RunMacroText('/cancelaura " + WoWSpell.FromId(25780) + "');");
                                       //Lua.DoString("CancelUnitBuff(\"Player\",\"Righteous Fury\")");
                                       return RunStatus.Failure;
                                   }))
                );
        }

        #endregion

        #region SacredShieldFriendRet

        private Composite SacredShieldFriendRet()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SSacredShieldRet &&
                SpellManager.HasSpell("Sacred Shield") &&
                !Me.Mounted &&
                !CastingorGCDL() &&
                Me.HealthPercent > THSettings.Instance.SPriorityHeal &&
                UnitHeal != null && UnitHeal.IsValid &&
                UnitHeal.HealthPercent < Me.HealthPercent - 20 &&
                !MyAura(20925, UnitHeal) &&
                GetSpellCooldown("Sacred Shield").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Sacred Shield", UnitHeal);
                               })
                );
        }

        #endregion

        #region SacredShieldMeRet

        private Composite SacredShieldMeProt()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SSacredShieldRet &&
                SpellManager.HasSpell("Sacred Shield") &&
                !Me.Mounted &&
                !Me.HasAura("Hand of Protection") &&
                !Me.HasAura("Divine Shield") &&
                !CastingorGCDL() &&
                (Me.Combat ||
                 Me.IsInInstance) &&
                (!Me.HasAura("Sacred Shield") ||
                 MyAuraTimeLeft("Sacred Shield", Me) < 2000) &&
                GetSpellCooldown("Sacred Shield").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Sacred Shield", Me);
                               })
                );
        }

        #endregion

        #region SacredShieldMeRet

        private Composite SacredShieldMeRet()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SSacredShieldRet &&
                SpellManager.HasSpell("Sacred Shield") &&
                !Me.Mounted &&
                !Me.HasAura("Hand of Protection") &&
                !Me.HasAura("Divine Shield") &&
                !CastingorGCDL() &&
                (Me.Combat &&
                 Me.HealthPercent < THSettings.Instance.SPriorityHeal ||
                 Me.CurrentMap.IsArena &&
                 !GetUnitHaveMySacredShield() ||
                 Me.CurrentMap.IsBattleground &&
                 !GetUnitHaveMySacredShield()) &&
                (!Me.HasAura("Sacred Shield") ||
                 MyAuraTimeLeft("Sacred Shield", Me) < 2000) &&
                GetSpellCooldown("Sacred Shield").TotalMilliseconds <= _myLatency,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Sacred Shield", Me);
                               })
                );
        }

        #endregion

        #region Survive Rotation

        private Composite CrowdControlSurviveComp()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    !Me.Mounted &&
                    THSettings.Instance.SCrowdControl != 0 &&
                    SpellManager.HasSpell("Blinding Light") &&
                    Me.HealthPercent < THSettings.Instance.SCrowdControl &&
                    !Me.HasAura("Divine Shield") &&
                    !Me.HasAura("Hand of Protection") &&
                    _lastCastSpell != "Devotion Aura" &&
                    _lastCastSpell != "Divine Shield" &&
                    _lastCastSpell != "Divine Shield" &&
                    GetSpellCooldown("Blinding Light").TotalMilliseconds <= _myLatency &&
                    CountEneyTargettingUnit(Me, 10) > 1,
                    new Action(delegate
                                   {
                                       CastSpell("Blinding Light", Me);
                                       Lua.DoString("RunMacroText('/stopattack');");
                                   })
                    ),
                //This is an bad idea
                //new Decorator(
                //    ret =>
                //    !Me.Mounted &&
                //    Me.HealthPercent < THSettings.Instance.SCrowdControl &&
                //    !Me.HasAura("Divine Shield") &&
                //    !Me.HasAura("Hand of Protection") &&
                //    !Me.IsMoving &&
                //    SpellManager.HasSpell("Repentance") &&
                //    SpellManager.Spells["Repentance"].CooldownTimeLeft.TotalMilliseconds <= MyLatency &&
                //    GetUnitCroudControlSurvive(30) && UnitCroudControlSurvive.IsValid,
                //    new Action(delegate
                //                   {
                //                       CastSpell("Repentance", UnitCroudControlSurvive);
                //                       Lua.DoString("RunMacroText('/stopattack');");
                //                   })
                //    ),
                new Decorator(
                    ret =>
                    THSettings.Instance.SCrowdControl != 0 &&
                    SpellManager.HasSpell("Fist of Justice") &&
                    !Me.Mounted &&
                    Me.HealthPercent < THSettings.Instance.SCrowdControl &&
                    !Me.HasAura("Divine Shield") &&
                    !Me.HasAura("Hand of Protection") &&
                    GetUnitCroudControlSurvive(20) &&
                    _unitCroudControlSurvive.IsValid &&
                    !InvulnerableStun(_unitCroudControlSurvive) &&
                    GetSpellCooldown("Hammer of Justice").TotalMilliseconds <= _myLatency,
                    new Action(delegate { CastSpell("Hammer of Justice", _unitCroudControlSurvive); })
                    ),
                new Decorator(
                    ret =>
                    THSettings.Instance.SCrowdControl != 0 &&
                    SpellManager.HasSpell("Hammer of Justice") &&
                    !Me.Mounted &&
                    Me.HealthPercent < THSettings.Instance.SCrowdControl &&
                    !Me.HasAura("Divine Shield") &&
                    !Me.HasAura("Hand of Protection") &&
                    GetUnitCroudControlSurvive(10) &&
                    _unitCroudControlSurvive.IsValid &&
                    !InvulnerableStun(_unitCroudControlSurvive) &&
                    GetSpellCooldown("Hammer of Justice").TotalMilliseconds <= _myLatency,
                    new Action(delegate { CastSpell("Hammer of Justice", _unitCroudControlSurvive); })
                    )
                )
                ;
        }

        #endregion

        #region SealofInsight

        private Composite SealofInsight()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Seal of Insight") &&
                !Me.Mounted &&
                !CastingorGCDL() &&
                !Me.HasAura("Seal of Insight") &&
                !Me.HasAura("Seal of Truth"),
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Seal of Insight", Me);
                               })
                );
        }

        #endregion

        #region SealofRighteousness

        private Composite SealofRighteousness()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SUnittoSealofRighteousness > 3 &&
                SpellManager.HasSpell("Seal of Righteousness") &&
                !Me.Mounted &&
                !CastingorGCDL() &&
                !Me.CurrentMap.IsBattleground &&
                !Me.CurrentMap.IsArena &&
                !Me.HasAura("Seal of Righteousness") &&
                CountEneyNeary(Me, 8) >= THSettings.Instance.SUnittoSealofRighteousness,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Seal of Righteousness", Me);
                               })
                );
        }

        #endregion

        #region Shield of the Righteous

        private Composite ShieldoftheRighteous()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SShieldoftheRighteous &&
                SpellManager.HasSpell("Shield of the Righteous") &&
                Me.HealthPercent > THSettings.Instance.SWordofGloryMeRet &&
                !Me.Mounted &&
                !Me.HasAura("Hand of Protection") &&
                Attackable(Me.CurrentTarget, 5) &&
                FacingOverride(Me.CurrentTarget) &&
                (Me.CurrentHolyPower >= 3 ||
                 Me.HasAura("Divine Purpose")) &&
                !CastingorGCDL() &&
                Me.Inventory.Equipped.OffHand != null
                ,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   SafelyFacingTarget(Me.CurrentTarget);
                                   CastSpell("Shield of the Righteous", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region SealofTruth

        private Composite SealofTruth()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    SpellManager.HasSpell("Seal of Truth") &&
                    !Me.Mounted &&
                    !CastingorGCDL() &&
                    !Me.HasAura("Seal of Truth") &&
                    !Me.HasAura("Seal of Righteousness") &&
                    !Me.HasAura("Seal of Justice") &&
                    !Me.HasAura("Seal of Insight"),
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                       CastSpell("Seal of Truth", Me);
                                   })
                    ),
                new Decorator(
                    ret =>
                    !SpellManager.HasSpell("Seal of Truth") &&
                    SpellManager.HasSpell("Seal of Command") &&
                    !Me.Mounted &&
                    !CastingorGCDL() &&
                    !Me.HasAura("Seal of Command"),
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                       CastSpell("Seal of Command", Me);
                                   })
                    ));
        }

        #endregion

        #region SealofTruth

        //private Composite SealofTruthProt()
        //{
        //    return new Decorator(
        //        ret =>
        //        !Me.Mounted &&
        //        !CastingorGCDL() &&
        //        SpellManager.HasSpell("Seal of Truth") &&
        //        !Me.HasAura("Seal of Truth") &&
        //        !Me.HasAura("Seal of Righteousness") &&
        //        !Me.HasAura("Seal of Insight"),
        //        new Action(delegate
        //            {
        //                //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
        //                CastSpell("Seal of Truth", Me);
        //                return RunStatus.Failure;
        //            })
        //        );
        //}

        #endregion

        #region SealofTruthfromRighteousness

        private Composite SealofTruthfromRighteousness()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SUnittoStartAoE >= 2 &&
                SpellManager.HasSpell("Seal of Truth") &&
                !Me.Mounted &&
                !CastingorGCDL() &&
                !Me.HasAura("Seal of Truth") &&
                !Me.HasAura("Seal of Insight") &&
                !Me.HasAura("Seal of Justice") &&
                CountEneyNeary(Me, 8) <= THSettings.Instance.SUnittoStartAoE,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Seal of Truth", Me);
                               })
                );
        }

        #endregion

        #region SealProtection

        public string ProtPreferedSeal;

        private Composite SealProtection()
        {
            return new PrioritySelector(
                //new Decorator(
                //    ret =>
                //    !Me.Mounted &&
                //    !CastingorGCDL(),
                //    new Action(delegate
                //        {
                //            if (Me.HasAura("Seal of Truth"))
                //            {
                //                ProtPreferedSeal = "Seal of Truth";
                //            }
                //            else
                //            {
                //                ProtPreferedSeal = "Seal of Insight";
                //            }
                //            return RunStatus.Failure;
                //        })),
                new Decorator(
                    ret =>
                    SpellManager.HasSpell("Seal of Command") &&
                    !Me.Mounted &&
                    !CastingorGCDL() &&
                    !Me.HasAura("Seal of Command"),
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                       CastSpell("Seal of Command", Me);
                                   })),
                new Decorator(
                    ret =>
                    SpellManager.HasSpell("Seal of Insight") &&
                    !Me.Mounted &&
                    !CastingorGCDL() &&
                    !Me.HasAura("Seal of Truth") &&
                    !Me.HasAura("Seal of Insight") &&
                    !Me.HasAura("Seal of Righteousness"),
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                       CastSpell("Seal of Insight", Me);
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SUnittoSealofRighteousness > 3 &&
                    SpellManager.HasSpell("Seal of Righteousness") &&
                    !Me.Mounted &&
                    Me.Combat &&
                    !CastingorGCDL() &&
                    !Me.CurrentMap.IsBattleground &&
                    !Me.CurrentMap.IsArena &&
                    !Me.HasAura("Seal of Righteousness") &&
                    CountEneyNeary(Me, 8) >= THSettings.Instance.SUnittoSealofRighteousness,
                    new Action(delegate
                                   {
                                       if (Me.HasAura("Seal of Truth"))
                                       {
                                           ProtPreferedSeal = "Seal of Truth";
                                       }
                                       else if (Me.HasAura("Seal of Command"))
                                       {
                                           ProtPreferedSeal = "Seal of Command";
                                       }
                                       else if (Me.HasAura("Seal of Insight"))
                                       {
                                           ProtPreferedSeal = "Seal of Insight";
                                       }
                                       //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                       CastSpell("Seal of Righteousness", Me);
                                   })),
                new Decorator(
                    ret =>
                    SpellManager.HasSpell(ProtPreferedSeal) &&
                    !Me.Mounted &&
                    //Me.Combat &&
                    !CastingorGCDL() &&
                    ProtPreferedSeal != null &&
                    !Me.HasAura(ProtPreferedSeal) &&
                    CountEneyNeary(Me, 8) < 4,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                       CastSpell(ProtPreferedSeal, Me);
                                   }))
                );
        }

        #endregion

        #region StopCastingCheck

        private void StopCastingCheck()
        {
            //Stop Casting Healing Spells
            if (Me.IsCasting &&
                (Me.CastingSpell.Name == "Holy Light" && _lastCastSpell == "Holy Light" ||
                 Me.CastingSpell.Name == "Flash of Light" && _lastCastSpell == "Flash of Light" ||
                 Me.CastingSpell.Name == "Divine Light" && _lastCastSpell == "Divine Light"))
            {
                if (_lastCastUnit != null && (!_lastCastUnit.IsValid || !_lastCastUnit.IsAlive))
                {
                    UnitHeal = null;
                    SpellManager.StopCasting();
                    Blacklist.Add(_lastCastUnit.Guid, BlacklistFlags.All, TimeSpan.FromSeconds(1));
                    Logging.Write(DateTime.Now.ToString("ss:fff ") + "Stop Casting: Unit is Dead");
                }
                else
                {
                    if (Me.IsCasting && _lastCastUnit != null && _lastCastUnit.IsValid &&
                        Me.CastingSpell.Name == "Divine Light" &&
                        (_lastCastUnit.HealthPercent >= THSettings.Instance.SDoNotHealAbove
                         ||
                         _lastCastUnit.HealthPercent >= THSettings.Instance.SDivineLight + 25))
                    {
                        SpellManager.StopCasting();
                        Logging.Write(DateTime.Now.ToString("ss:fff ") + "Stop Casting: Save Mana Divine Light");
                    }

                    if (Me.IsCasting && _lastCastUnit != null && _lastCastUnit.IsValid &&
                        Me.CastingSpell.Name == "Flash of Light" && SpellManager.HasSpell("Holy Light") &&
                        (_lastCastUnit.HealthPercent >= THSettings.Instance.SDoNotHealAbove
                         || _lastCastUnit.HealthPercent >= THSettings.Instance.SFlashofLight + 20))
                    {
                        SpellManager.StopCasting();
                        Logging.Write(DateTime.Now.ToString("ss:fff ") + "Stop Casting: Save Mana Flash of Light");
                    }

                    if (!Me.CurrentMap.IsDungeon && !Me.CurrentMap.IsRaid &&
                        Me.IsCasting && _lastCastUnit != null && _lastCastUnit.IsValid &&
                        Me.CastingSpell.Name == "Holy Light" &&
                        Me.CurrentCastTimeLeft.TotalMilliseconds > 1300 &&
                        _lastCastUnit.HealthPercent < THSettings.Instance.SDivineLight &&
                        (_lastCastUnit.Combat || Me.Combat))
                    {
                        SpellManager.StopCasting();
                        Logging.Write(DateTime.Now.ToString("ss:fff ") + "Stop Casting Holy Light. Need Faster Heal!");
                    }

                    if (Me.IsCasting &&
                        Me.CastingSpell.Name == "Divine Light" && Me.GetAuraById(54149) == null &&
                        (Me.CurrentMap.IsBattleground || Me.CurrentMap.IsArena))
                    {
                        SpellManager.StopCasting();
                        Logging.Write(DateTime.Now.ToString("ss:fff ") + "Stop Casting " + _lastCastSpell +
                                      ": No Infusion of Light");
                    }

                    if (Me.IsCasting && Me.CastingSpell.Name != "Holy Light" && _lastCastUnit != null &&
                        _lastCastUnit.IsValid &&
                        _lastCastUnit.HealthPercent > THSettings.Instance.SDoNotHealAbove)
                    {
                        UnitHeal = null;
                        SpellManager.StopCasting();
                        Blacklist.Add(_lastCastUnit.Guid, BlacklistFlags.All, TimeSpan.FromSeconds(1));
                        Logging.Write(DateTime.Now.ToString("ss:fff ") + "Stop Casting: Unit Full HP");
                    }

                    if (Me.IsCasting && _lastCastUnit != null && _lastCastUnit.IsValid &&
                        !_lastCastUnit.InLineOfSpellSight)
                    {
                        UnitHeal = null;

                        SpellManager.StopCasting();
                        Blacklist.Add(_lastCastUnit.Guid, BlacklistFlags.All, TimeSpan.FromSeconds(1));
                        Logging.Write(DateTime.Now.ToString("ss:fff ") + "Stop Casting: Unit not In Line of Spell Sight");
                    }

                    if (Me.IsCasting && _lastCastUnit != null && _lastCastUnit.IsValid &&
                        GetMaxDistance(_lastCastUnit) > 40)
                    {
                        UnitHeal = null;
                        SpellManager.StopCasting();
                        Blacklist.Add(_lastCastUnit.Guid, BlacklistFlags.All, TimeSpan.FromSeconds(1));
                        Logging.Write(DateTime.Now.ToString("ss:fff ") + "Stop Casting: Unit out of range");
                    }
                }
            }

            //Stop Casting Denounce
            if (Me.IsCasting && Me.CastingSpell.Name == "Denounce" && _lastCastSpell == "Denounce")
            {
                if (_lastCastUnit != null && (!_lastCastUnit.IsValid || !_lastCastUnit.IsAlive))
                {
                    UnitAttack = null;
                    SpellManager.StopCasting();
                    Blacklist.Add(_lastCastUnit.Guid, BlacklistFlags.All, TimeSpan.FromSeconds(1));
                    Logging.Write(DateTime.Now.ToString("ss:fff ") + "Stop Casting: Unit is Dead");
                }
                else
                {
                    if (Me.IsCasting && _lastCastUnit != null && _lastCastUnit.IsValid &&
                        !_lastCastUnit.InLineOfSpellSight)
                    {
                        UnitAttack = null;
                        SpellManager.StopCasting();
                        Blacklist.Add(_lastCastUnit.Guid, BlacklistFlags.All, TimeSpan.FromSeconds(1));
                        Logging.Write(DateTime.Now.ToString("ss:fff ") + "Stop Casting: Unit not In Line of Spell Sight");
                    }
                    if (Me.IsCasting && _lastCastUnit != null && _lastCastUnit.IsValid &&
                        GetMaxDistance(_lastCastUnit) > 30)
                    {
                        UnitAttack = null;
                        SpellManager.StopCasting();
                        Blacklist.Add(_lastCastUnit.Guid, BlacklistFlags.All, TimeSpan.FromSeconds(1));
                        Logging.Write(DateTime.Now.ToString("ss:fff ") + "Stop Casting: Unit out of range");
                    }

                    if (Me.IsCasting && _lastCastUnit != null && _lastCastUnit.IsValid &&
                        DebuffCCBreakonDamage(_lastCastUnit))
                    {
                        UnitAttack = null;
                        SpellManager.StopCasting();
                        Blacklist.Add(_lastCastUnit.Guid, BlacklistFlags.All, TimeSpan.FromSeconds(1));
                        Logging.Write(DateTime.Now.ToString("ss:fff ") +
                                      "Stop Casting: Unit Have Debuff Break on Damage");
                    }
                    if (UnitHeal != null && UnitHeal.IsValid &&
                        UnitHeal.HealthPercent < THSettings.Instance.SPriorityHeal)
                    {
                        SpellManager.StopCasting();
                        Logging.Write(DateTime.Now.ToString("ss:fff ") + "Stop Casting Denounce: Need Heal First");
                    }
                }
            }

            //Stop Casting Repentance
            if (Me.IsCasting && Me.CastingSpell.Name == "Repentance" && _lastCastSpell == "Repentance")
            {
                if (_lastCastUnit != null && (!_lastCastUnit.IsValid || !_lastCastUnit.IsAlive))
                {
                    UnitAttack = null;
                    SpellManager.StopCasting();
                    Blacklist.Add(_lastCastUnit.Guid, BlacklistFlags.All, TimeSpan.FromSeconds(1));
                    Logging.Write(DateTime.Now.ToString("ss:fff ") + "Stop Casting: Unit is Dead");
                }
                else
                {
                    if (Me.IsCasting && _lastCastUnit != null && _lastCastUnit.IsValid &&
                        !_lastCastUnit.InLineOfSpellSight)
                    {
                        UnitAttack = null;
                        SpellManager.StopCasting();
                        Blacklist.Add(_lastCastUnit.Guid, BlacklistFlags.All, TimeSpan.FromSeconds(1));
                        Logging.Write(DateTime.Now.ToString("ss:fff ") + "Stop Casting: Unit not In Line of Spell Sight");
                    }
                    if (Me.IsCasting && _lastCastUnit != null && _lastCastUnit.IsValid &&
                        GetMaxDistance(_lastCastUnit) > 30)
                    {
                        UnitAttack = null;
                        SpellManager.StopCasting();
                        Blacklist.Add(_lastCastUnit.Guid, BlacklistFlags.All, TimeSpan.FromSeconds(1));
                        Logging.Write(DateTime.Now.ToString("ss:fff ") + "Stop Casting: Unit out of range");
                    }

                    if (Me.IsCasting && _lastCastUnit != null && _lastCastUnit.IsValid && DebuffCC(_lastCastUnit) > 0)
                    {
                        UnitAttack = null;
                        SpellManager.StopCasting();
                        Blacklist.Add(_lastCastUnit.Guid, BlacklistFlags.All, TimeSpan.FromSeconds(1));
                        Logging.Write(DateTime.Now.ToString("ss:fff ") + "Stop Casting: Unit is Croud Controlled");
                    }
                    if (UnitHeal != null && UnitHeal.IsValid &&
                        UnitHeal.HealthPercent < THSettings.Instance.SPriorityHeal)
                    {
                        SpellManager.StopCasting();
                        Logging.Write(DateTime.Now.ToString("ss:fff ") + "Stop Casting Denounce: Need Heal First");
                    }
                }
            }
        }

        #endregion

        #region TemplarsVerdict3HolyPower

        private Composite TemplarsVerdict3HolyPower()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.STemplarsVerdict &&
                SpellManager.HasSpell("Templar's Verdict") &&
                !Me.Mounted &&
                !Me.HasAura("Hand of Protection") &&
                Attackable(Me.CurrentTarget, 5) &&
                FacingOverride(Me.CurrentTarget) &&
                (Me.CurrentHolyPower >= 3 ||
                 Me.HasAura("Divine Purpose")) &&
                !CastingorGCDL(),
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   SafelyFacingTarget(Me.CurrentTarget);
                                   CastSpell("Templar's Verdict", Me.CurrentTarget);
                               })
                );
        }

        #endregion

        #region TemplarsVerdict5HolyPower

        private Composite TemplarsVerdict5HolyPower()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.STemplarsVerdict &&
                SpellManager.HasSpell("Templar's Verdict") &&
                !Me.Mounted &&
                !Me.HasAura("Hand of Protection") &&
                Attackable(Me.CurrentTarget, 5) &&
                FacingOverride(Me.CurrentTarget) &&
                (Me.CurrentHolyPower == Me.MaxHolyPower ||
                 Me.HasAura("Divine Purpose") ||
                 Me.CurrentHolyPower >= 3 &&
                 Me.HasAura("Holy Avenger")) &&
                !CastingorGCDL()
                ,
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   SafelyFacingTarget(Me.CurrentTarget);
                                   CastSpell("Templar's Verdict", Me.CurrentTarget);
                               }));
        }

        #endregion

        #region TurnEvilComp

        private WoWUnit _unitTurnEvilASAP;

        private bool GetUnitTurnEvilASAP()
        {
            _unitTurnEvilASAP = null;

            //using (StyxWoW.Memory.AcquireFrame())
            {
                _unitTurnEvilASAP = (from unit in NearbyUnFriendlyUnits
                                     where unit != null
                                     orderby unit.MaxHealth descending
                                     where
                                         unit.HasAura("Lichborne") ||
                                         unit.HasAura("Dark Transformation") ||
                                         unit.Name == "Ebon Gargoyle" ||
                                         unit.IsChanneling &&
                                         (unit.ChanneledSpell.Name == "Mesmerize" ||
                                          unit.ChanneledSpell.Name == "Seduction")
                                     where GetMinDistance(unit) < 20
                                     where DebuffCC(unit) <= 0
                                     where !Invulnerable(unit)
                                     where !InvulnerableMagic(unit)
                                     where AttackableValid(unit)
                                     select unit).FirstOrDefault();
            }
            //if (UnitTurnEvilASAP != null)
            //{
            //    Logging.Write("Found UnitTurnEvilASAP " + UnitTurnEvilASAP.Name);
            //}
            return _unitTurnEvilASAP != null;
        }

        private WoWUnit _unitTurnEvil;

        private bool GetUnitTurnEvil()
        {
            _unitTurnEvil = null;

            //using (StyxWoW.Memory.AcquireFrame())
            {
                _unitTurnEvil = (from unit in NearbyUnFriendlyUnits
                                 where AttackableValid(unit)
                                 orderby unit.Distance ascending
                                 //where unit.IsPet
                                 where unit.IsDemon || unit.IsUndead
                                 where GetMinDistance(unit) < 20
                                 where !unit.Name.Contains("Army")
                                 where !Invulnerable(unit)
                                 //where !InvulnerableMagic(unit)
                                 where DebuffCC(unit) <= 0
                                 select unit).FirstOrDefault();
            }
            //if (UnitTurnEvil != null)
            //{
            //    Logging.Write("Found UnitTurnEvil " + UnitTurnEvil.Name);
            //}
            return _unitTurnEvil != null;
        }

        private Composite TurnEvilComp()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    THSettings.Instance.STurnEvil &&
                    SpellManager.HasSpell("Turn Evil") &&
                    Me.Combat &&
                    HasGlyph.Contains("54931") &&
                    GetUnitTurnEvil() &&
                    _unitTurnEvil != null &&
                    _unitTurnEvil.IsValid &&
                    _unitTurnEvil.Distance < 20 &&
                    !CastingorGCDL() &&
                    GetSpellCooldown("Turn Evil").TotalMilliseconds <= _myLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Found UnitTurnEvil");
                                       CastSpell("Turn Evil", _unitTurnEvil);
                                       _unitTurnEvilASAP = null;
                                   }))
                );
        }

        private Composite TurnEvilASAPComp()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    THSettings.Instance.STurnEvil &&
                    SpellManager.HasSpell("Turn Evil") &&
                    Me.Combat &&
                    HasGlyph.Contains("54931") &&
                    GetUnitTurnEvilASAP() &&
                    _unitTurnEvilASAP != null &&
                    _unitTurnEvilASAP.IsValid &&
                    _unitTurnEvilASAP.Distance < 20 &&
                    !CastingorGCDL() &&
                    GetSpellCooldown("Turn Evil").TotalMilliseconds <= _myLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Found UnitTurnEvil");
                                       CastSpell("Turn Evil", _unitTurnEvilASAP);
                                       _unitTurnEvilASAP = null;
                                   }))
                );
        }

        #endregion

        #region UseRacial

        private Composite UseRacial()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    THSettings.Instance.SRacial &&
                    SpellManager.HasSpell("Every Man for Himself") &&
                    Me.Combat &&
                    DebuffCC(Me) > 3000 &&
                    !Me.HasAura("Sap") &&
                    GetSpellCooldown("Every Man for Himself").TotalMilliseconds <= _myLatency,
                    new Action(delegate
                                   {
                                       if (THSettings.Instance.SAutoTarget && Me.CurrentTarget == null &&
                                           ValidUnit(MyLastTarget))
                                       {
                                           MyLastTarget.Target();
                                       }

                                       if (DebuffCCBreakonDamage(Me) &&
                                           DotAll(Me) > 0)
                                       {
                                           Logging.Write("Waiting for Dot / Hand of Sacrifice break it!");
                                       }
                                       else
                                       {
                                           Logging.Write("Use: Every Man for Himself");
                                           CastSpell("Every Man for Himself", Me);
                                       }
                                       return RunStatus.Failure;
                                   })),
                //Stoneform
                new Decorator(
                    ret =>
                    THSettings.Instance.SRacial && Me.HealthPercent < THSettings.Instance.SUrgentHeal &&
                    SpellManager.HasSpell("Stoneform") &&
                    Me.Combat &&
                    GetSpellCooldown("Stoneform").TotalMilliseconds <= _myLatency,
                    new Action(delegate
                                   {
                                       {
                                           Logging.Write("Stoneform");
                                           CastSpell("Stoneform", Me);
                                       }
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SRacial && Me.HealthPercent < THSettings.Instance.SUrgentHeal &&
                    SpellManager.HasSpell("Gift of the Naaru") &&
                    Me.Combat &&
                    GetSpellCooldown("Gift of the Naaru").TotalMilliseconds <= _myLatency,
                    new Action(delegate
                                   {
                                       {
                                           Logging.Write("Gift of the Naaru");
                                           CastSpell("Gift of the Naaru", Me);
                                       }
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SRacial && Me.ManaPercent < THSettings.Instance.SPriorityHeal &&
                    SpellManager.HasSpell("Arcane Torrent") && SpellManager.HasSpell("Holy Insight") &&
                    Me.Combat &&
                    (Me.CurrentMap.IsDungeon || Me.CurrentMap.IsRaid) &&
                    GetSpellCooldown("Arcane Torrent").TotalMilliseconds <= _myLatency,
                    new Action(delegate
                                   {
                                       {
                                           Logging.Write("Arcane Torrent");
                                           CastSpell("Arcane Torrent", Me);
                                       }
                                       return RunStatus.Failure;
                                   }))
                );
        }

        #endregion

        #region UseTrinket

        private Composite UseTrinket()
        {
            return new PrioritySelector(
                new Decorator(
                    ret =>
                    THSettings.Instance.STrinket1 == 1 &&
                    _lastCastSpell != "STrinket1" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1),
                    new Action(delegate
                                   {
                                       Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                                     " on Cooldown");
                                       StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                                       _lastCastSpell = "STrinket1";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.STrinket1 == 2 &&
                    _lastCastSpell != "STrinket1" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1) &&
                    THSettings.Instance.SBurst,
                    new Action(delegate
                                   {
                                       Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                                     " on Burst Mode");
                                       StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                                       _lastCastSpell = "STrinket1";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.STrinket1 == 3 &&
                    _lastCastSpell != "STrinket1" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1) &&
                    DebuffCC(Me) > 3000 && !Me.HasAura("Sap"),
                    new Action(delegate
                                   {
                                       Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                                     " on Lose Control");
                                       StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                                       _lastCastSpell = "STrinket1";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.STrinket1 == 4 &&
                    _lastCastSpell != "STrinket1" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1) &&
                    Me.HealthPercent < THSettings.Instance.STrinket1HP,
                    new Action(delegate
                                   {
                                       Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                                     " on Low HP");
                                       StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                                       _lastCastSpell = "STrinket1";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.STrinket1 == 5 &&
                    _lastCastSpell != "STrinket1" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1) &&
                    UnitHeal != null && UnitHeal.IsValid && UnitHeal.IsAlive &&
                    UnitHeal.HealthPercent < THSettings.Instance.STrinket1HP,
                    new Action(delegate
                                   {
                                       Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                                     " on Friendly Unit Low HP");
                                       StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                                       _lastCastSpell = "STrinket1";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.STrinket1 == 6 &&
                    _lastCastSpell != "STrinket1" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1) &&
                    Me.CurrentTarget != null && Me.CurrentTarget.IsValid &&
                    IsEnemy(Me.CurrentTarget) && !Me.CurrentTarget.IsPet &&
                    Me.CurrentTarget.Distance < 10 &&
                    Me.CurrentTarget.HealthPercent < THSettings.Instance.STrinket1HP,
                    new Action(delegate
                                   {
                                       Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                                     " on Enemy Unit Low HP");
                                       StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                                       _lastCastSpell = "STrinket1";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.STrinket1 == 7 &&
                    _lastCastSpell != "STrinket1" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Trinket1 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket1) &&
                    Me.ManaPercent < THSettings.Instance.STrinket1HP,
                    new Action(delegate
                                   {
                                       Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name +
                                                     " on Low Mana");
                                       StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                                       _lastCastSpell = "STrinket1";
                                       return RunStatus.Failure;
                                   })),
                //Trinket 2
                new Decorator(
                    ret =>
                    THSettings.Instance.STrinket2 == 1 &&
                    _lastCastSpell != "STrinket2" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2),
                    new Action(delegate
                                   {
                                       Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                                     " on Cooldown");
                                       StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                                       _lastCastSpell = "STrinket2";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.STrinket2 == 2 &&
                    _lastCastSpell != "STrinket2" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2) &&
                    THSettings.Instance.SBurst,
                    new Action(delegate
                                   {
                                       Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                                     " on Burst Mode");
                                       StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                                       _lastCastSpell = "STrinket2";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.STrinket2 == 3 &&
                    _lastCastSpell != "STrinket2" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2) &&
                    DebuffCC(Me) > 3000 && !Me.HasAura("Sap"),
                    new Action(delegate
                                   {
                                       Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                                     " on Lose Control");
                                       StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                                       _lastCastSpell = "STrinket2";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.STrinket2 == 4 &&
                    _lastCastSpell != "STrinket2" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2) &&
                    Me.HealthPercent < THSettings.Instance.STrinket2HP,
                    new Action(delegate
                                   {
                                       Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                                     " on Low HP");
                                       StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                                       _lastCastSpell = "STrinket2";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.STrinket2 == 5 &&
                    _lastCastSpell != "STrinket2" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2) &&
                    UnitHeal != null && UnitHeal.IsValid && UnitHeal.IsAlive &&
                    UnitHeal.HealthPercent < THSettings.Instance.STrinket2HP,
                    new Action(delegate
                                   {
                                       Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                                     " on Friendly Unit Low HP");
                                       StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                                       _lastCastSpell = "STrinket2";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.STrinket2 == 6 &&
                    _lastCastSpell != "STrinket2" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2) &&
                    Me.CurrentTarget != null && Me.CurrentTarget.IsValid &&
                    IsEnemy(Me.CurrentTarget) && !Me.CurrentTarget.IsPet &&
                    Me.CurrentTarget.Distance < 10 &&
                    Me.CurrentTarget.HealthPercent < THSettings.Instance.STrinket2HP,
                    new Action(delegate
                                   {
                                       Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                                     " on Enemy Unit Low HP");
                                       StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                                       _lastCastSpell = "STrinket2";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.STrinket2 == 7 &&
                    _lastCastSpell != "STrinket2" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Trinket2 != null &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Trinket2) &&
                    Me.ManaPercent < THSettings.Instance.STrinket1HP,
                    new Action(delegate
                                   {
                                       Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name +
                                                     " on Low Mana");
                                       StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                                       _lastCastSpell = "STrinket2";
                                       return RunStatus.Failure;
                                   }))
                );
        }

        #endregion

        #region UseProfession

        private Composite UseProfession()
        {
            return new PrioritySelector(
                //Engineering
                new Decorator(
                    ret =>
                    THSettings.Instance.SProfBuff == 1 &&
                    _lastCastSpell != "SProfBuff" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Hands != null &&
                    (Me.Inventory.Equipped.Hands.GetEnchantment("Phase Fingers") != null ||
                     Me.Inventory.Equipped.Hands.GetEnchantment("Synapse Springs") != null ||
                     Me.Inventory.Equipped.Hands.GetEnchantment("Incendiary Fireworks Launcher") != null &&
                     ValidUnit(Me.CurrentTarget) &&
                     IsEnemy(Me.CurrentTarget) &&
                     Me.CurrentTarget.Distance < 30 &&
                     Me.CurrentTarget.InLineOfSpellSight) &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands) &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands),
                    new Action(delegate
                                   {
                                       Logging.Write("Use: Gloves Buff Activated on Cooldown");
                                       StyxWoW.Me.Inventory.Equipped.Hands.Use();
                                       _lastCastSpell = "SProfBuff";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SProfBuff == 2 &&
                    _lastCastSpell != "SProfBuff" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Hands != null &&
                    (Me.Inventory.Equipped.Hands.GetEnchantment("Phase Fingers") != null ||
                     Me.Inventory.Equipped.Hands.GetEnchantment("Synapse Springs") != null ||
                     Me.Inventory.Equipped.Hands.GetEnchantment("Incendiary Fireworks Launcher") != null &&
                     ValidUnit(Me.CurrentTarget) &&
                     IsEnemy(Me.CurrentTarget) &&
                     Me.CurrentTarget.Distance < 30 &&
                     Me.CurrentTarget.InLineOfSpellSight) &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands),
                    new Action(delegate
                                   {
                                       Logging.Write("Use: Gloves Buff Activated on Burst Mode");
                                       StyxWoW.Me.Inventory.Equipped.Hands.Use();
                                       _lastCastSpell = "SProfBuff";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SProfBuff == 3 &&
                    _lastCastSpell != "SProfBuff" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Hands != null &&
                    (Me.Inventory.Equipped.Hands.GetEnchantment("Phase Fingers") != null ||
                     Me.Inventory.Equipped.Hands.GetEnchantment("Synapse Springs") != null ||
                     Me.Inventory.Equipped.Hands.GetEnchantment("Incendiary Fireworks Launcher") != null &&
                     ValidUnit(Me.CurrentTarget) &&
                     IsEnemy(Me.CurrentTarget) &&
                     Me.CurrentTarget.Distance < 30 &&
                     Me.CurrentTarget.InLineOfSpellSight) &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands) &&
                    DebuffCC(Me) > 3000,
                    new Action(delegate
                                   {
                                       Logging.Write("Use: Gloves Buff Activated on Lose Control");
                                       StyxWoW.Me.Inventory.Equipped.Hands.Use();
                                       _lastCastSpell = "SProfBuff";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SProfBuff == 4 &&
                    _lastCastSpell != "SProfBuff" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Hands != null &&
                    (Me.Inventory.Equipped.Hands.GetEnchantment("Phase Fingers") != null ||
                     Me.Inventory.Equipped.Hands.GetEnchantment("Synapse Springs") != null ||
                     Me.Inventory.Equipped.Hands.GetEnchantment("Incendiary Fireworks Launcher") != null &&
                     ValidUnit(Me.CurrentTarget) &&
                     IsEnemy(Me.CurrentTarget) &&
                     Me.CurrentTarget.Distance < 30 &&
                     Me.CurrentTarget.InLineOfSpellSight) &&
                    Me.HealthPercent < THSettings.Instance.SProfBuffHP &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands),
                    new Action(delegate
                                   {
                                       Logging.Write("Use: GLoves Buff Activated on Low HP");
                                       StyxWoW.Me.Inventory.Equipped.Hands.Use();
                                       _lastCastSpell = "SProfBuff";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SProfBuff == 5 &&
                    _lastCastSpell != "SProfBuff" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Hands != null &&
                    (Me.Inventory.Equipped.Hands.GetEnchantment("Phase Fingers") != null ||
                     Me.Inventory.Equipped.Hands.GetEnchantment("Synapse Springs") != null ||
                     Me.Inventory.Equipped.Hands.GetEnchantment("Incendiary Fireworks Launcher") != null &&
                     ValidUnit(Me.CurrentTarget) &&
                     IsEnemy(Me.CurrentTarget) &&
                     Me.CurrentTarget.Distance < 30 &&
                     Me.CurrentTarget.InLineOfSpellSight) &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands) &&
                    UnitHeal != null && UnitHeal.IsValid && UnitHeal.IsAlive &&
                    UnitHeal.HealthPercent < THSettings.Instance.SProfBuffHP,
                    new Action(delegate
                                   {
                                       Logging.Write("Use: Gloves Buff Activated on Friendly Unit Low HP");
                                       StyxWoW.Me.Inventory.Equipped.Hands.Use();
                                       _lastCastSpell = "SProfBuff";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SProfBuff == 6 &&
                    _lastCastSpell != "SProfBuff" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Hands != null &&
                    Me.Inventory.Equipped.Hands != null &&
                    (Me.Inventory.Equipped.Hands.GetEnchantment("Phase Fingers") != null ||
                     Me.Inventory.Equipped.Hands.GetEnchantment("Synapse Springs") != null ||
                     Me.Inventory.Equipped.Hands.GetEnchantment("Incendiary Fireworks Launcher") != null &&
                     ValidUnit(Me.CurrentTarget) &&
                     IsEnemy(Me.CurrentTarget) &&
                     Me.CurrentTarget.Distance < 30 &&
                     Me.CurrentTarget.InLineOfSpellSight) &&
                    Me.CurrentTarget != null && Me.CurrentTarget.IsValid &&
                    IsEnemy(Me.CurrentTarget) && !Me.CurrentTarget.IsPet &&
                    Me.CurrentTarget.IsWithinMeleeRange &&
                    Me.CurrentTarget.HealthPercent < THSettings.Instance.SProfBuffHP &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands),
                    new Action(delegate
                                   {
                                       Logging.Write("Use: Gloves Buff Activated on Enemy Unit Low HP");
                                       StyxWoW.Me.Inventory.Equipped.Hands.Use();
                                       _lastCastSpell = "SProfBuff";
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SProfBuff == 7 &&
                    _lastCastSpell != "SProfBuff" &&
                    Me.Combat &&
                    Me.Inventory.Equipped.Hands != null &&
                    (Me.Inventory.Equipped.Hands.GetEnchantment("Phase Fingers") != null ||
                     Me.Inventory.Equipped.Hands.GetEnchantment("Synapse Springs") != null ||
                     Me.Inventory.Equipped.Hands.GetEnchantment("Incendiary Fireworks Launcher") != null &&
                     ValidUnit(Me.CurrentTarget) &&
                     IsEnemy(Me.CurrentTarget) &&
                     Me.CurrentTarget.Distance < 30 &&
                     Me.CurrentTarget.InLineOfSpellSight) &&
                    CanUseEquippedItem(Me.Inventory.Equipped.Hands) &&
                    Me.ManaPercent < THSettings.Instance.SProfBuffHP,
                    new Action(delegate
                                   {
                                       Logging.Write("Use: Gloves Buff Activated on Low Mana");
                                       StyxWoW.Me.Inventory.Equipped.Hands.Use();
                                       _lastCastSpell = "SProfBuff";
                                       return RunStatus.Failure;
                                   })),
                //Herbalism
                new Decorator(
                    ret =>
                    THSettings.Instance.SProfBuff == 1 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    _lastCastSpell != "Lifeblood" &&
                    Me.Combat &&
                    GetSpellCooldown("Lifeblood").TotalMilliseconds <= _myLatency,
                    new Action(delegate
                                   {
                                       Logging.Write("Use: Lifeblood Activated on Cooldown");
                                       CastSpell("Lifeblood", Me);
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SProfBuff == 2 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    _lastCastSpell != "Lifeblood" &&
                    Me.Combat &&
                    GetSpellCooldown("Lifeblood").TotalMilliseconds <= _myLatency &&
                    THSettings.Instance.SBurst,
                    new Action(delegate
                                   {
                                       Logging.Write("Use: Lifeblood Activated on Burst Mode");
                                       CastSpell("Lifeblood", Me);
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SProfBuff == 3 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    _lastCastSpell != "Lifeblood" &&
                    Me.Combat &&
                    GetSpellCooldown("Lifeblood").TotalMilliseconds <= _myLatency &&
                    DebuffCC(Me) > 3000,
                    new Action(delegate
                                   {
                                       Logging.Write("Use: Lifeblood Activated on Lose Control");
                                       CastSpell("Lifeblood", Me);
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SProfBuff == 4 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    _lastCastSpell != "Lifeblood" &&
                    Me.Combat &&
                    GetSpellCooldown("Lifeblood").TotalMilliseconds <= _myLatency &&
                    Me.HealthPercent < THSettings.Instance.SProfBuffHP,
                    new Action(delegate
                                   {
                                       Logging.Write("Use: Lifeblood Activated on Low HP");
                                       CastSpell("Lifeblood", Me);
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SProfBuff == 5 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    _lastCastSpell != "Lifeblood" &&
                    Me.Combat &&
                    GetSpellCooldown("Lifeblood").TotalMilliseconds <= _myLatency &&
                    UnitHeal != null && UnitHeal.IsValid && UnitHeal.HealthPercent < THSettings.Instance.SProfBuffHP,
                    new Action(delegate
                                   {
                                       Logging.Write("Use: Lifeblood Activated on Friendly Unit Low HP");
                                       CastSpell("Lifeblood", Me);
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SProfBuff == 6 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    _lastCastSpell != "Lifeblood" &&
                    Me.Combat &&
                    GetSpellCooldown("Lifeblood").TotalMilliseconds <= _myLatency &&
                    Me.CurrentTarget != null && Me.CurrentTarget.IsValid &&
                    IsEnemy(Me.CurrentTarget) && !Me.CurrentTarget.IsPet &&
                    Me.CurrentTarget.IsWithinMeleeRange &&
                    Me.CurrentTarget.HealthPercent < THSettings.Instance.SProfBuffHP,
                    new Action(delegate
                                   {
                                       Logging.Write("Use: Lifeblood Activated on Enemy Unit Low HP");
                                       CastSpell("Lifeblood", Me);
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    THSettings.Instance.SProfBuff == 7 &&
                    SpellManager.HasSpell("Lifeblood") &&
                    _lastCastSpell != "Lifeblood" &&
                    Me.Combat &&
                    GetSpellCooldown("Lifeblood").TotalMilliseconds <= _myLatency &&
                    Me.ManaPercent < THSettings.Instance.SProfBuffHP,
                    new Action(delegate
                                   {
                                       Logging.Write("Use: Lifeblood Activated on Low Mana");
                                       CastSpell("Lifeblood", Me);
                                       return RunStatus.Failure;
                                   }))
                );
        }

        #endregion

        #region WarStomp

        private Composite WarStomp()
        {
            return new Decorator(
                ret =>
                THSettings.Instance.SRacial &&
                SpellManager.HasSpell("War Stomp") &&
                _lastInterrupt < DateTime.Now &&
                UnitHeal != null &&
                UnitHeal.IsValid &&
                UnitHeal.HealthPercent > THSettings.Instance.SPriorityHeal &&
                !Me.IsMoving &&
                SpellManager.Spells["War Stomp"].CooldownTimeLeft.TotalMilliseconds <= _myLatency &&
                GetUnitInterrupt(10, _myLatency + 500, THSettings.Instance.SHammerofJustice, false, false) &&
                _unitInterrupt != null && _unitInterrupt.IsValid,
                new Action(delegate
                               {
                                   if (Me.IsCasting)
                                   {
                                       SpellManager.StopCasting();
                                   }
                                   if (_unitInterrupt.IsCasting &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds >
                                       _myLatency + THSettings.Instance.SRebuke + 500)
                                   {
                                       return RunStatus.Running;
                                   }
                                   if (_unitInterrupt.IsCasting &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds <
                                       _myLatency + THSettings.Instance.SRebuke + 500 &&
                                       _unitInterrupt.CurrentCastTimeLeft.TotalMilliseconds > _myLatency + 500)
                                   {
                                       CastSpell("War Stomp", Me);
                                       _lastInterrupt = DateTime.Now + TimeSpan.FromSeconds(1);
                                       return RunStatus.Success;
                                   }
                                   return RunStatus.Failure;
                               }));
        }

        #endregion

        #region WordofGlory

        private Composite WordofGlory()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Word of Glory") &&
                !SpellManager.HasSpell("Eternal Flame") &&
                Healable(UnitHeal) &&
                !CastingorGCDL() &&
                !Blacklist.Contains(UnitHeal.Guid, BlacklistFlags.All) &&
                UnitHeal.HealthPercent <= THSettings.Instance.SWordofGlory &&
                (Me.CurrentHolyPower >= 3 ||
                 Me.HasAura("Divine Purpose")),
                new Action(delegate
                               {
                                   //_unitBeaconSecond = null;
                                   CastSpell("Word of Glory", UnitHeal);
                                   UnitHeal = null;
                               }));
        }

        #endregion

        #region WordofGloryMeTopUpRet

        private Composite WordofGloryMeTopUpRet()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Word of Glory") &&
                !Me.Mounted &&
                !Me.Combat &&
                (Me.CurrentHolyPower >= 1 ||
                 Me.HasAura("Divine Purpose")) &&
                !CastingorGCDL() &&
                !Me.CurrentMap.IsDungeon &&
                !Me.CurrentMap.IsRaid &&
                Me.HealthPercent <= THSettings.Instance.SDoNotHealAbove &&
                MyAuraTimeLeft(114163, Me) < 1000, //114163 Eternal Flame
                
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Word of Glory", Me);
                               })
                );
        }

        #endregion

        #region WordofGloryMeRet

        private Composite WordofGloryMeRet()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Word of Glory") &&
                !Me.Mounted &&
                Me.Combat &&
                THSettings.Instance.SWordofGloryMeRet != 0 &&
                (Me.CurrentHolyPower >= 3 ||
                 Me.HasAura("Divine Purpose")) &&
                !CastingorGCDL() &&
                !Me.CurrentMap.IsDungeon &&
                !Me.CurrentMap.IsRaid &&
                Me.HealthPercent <= THSettings.Instance.SWordofGloryMeRet &&
                MyAuraTimeLeft(114163, Me) < 2000, //114163 Eternal Flame
                
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Word of Glory", Me);
                               })
                );
        }

        #endregion

        #region WordofGloryMeProtection

        private Composite WordofGloryMeProtection()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Word of Glory") &&
                !Me.Mounted &&
                Me.Combat &&
                (Me.CurrentHolyPower >= 3 ||
                 Me.HasAura("Divine Purpose")) &&
                !CastingorGCDL() &&
                Me.HealthPercent <= THSettings.Instance.SWordofGloryMeRet &&
                MyAuraTimeLeft(114163, Me) < 2000, //114163 Eternal Flame
                
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Word of Glory", Me);
                               })
                );
        }

        #endregion

        #region WordofGloryFriendRet

        private Composite WordofGloryFriendRet()
        {
            return new Decorator(
                ret =>
                SpellManager.HasSpell("Word of Glory") &&
                !Me.Mounted &&
                Me.Combat &&
                THSettings.Instance.SWordofGloryFriendRet != 0 &&
                (Me.CurrentHolyPower >= 3 ||
                 Me.HasAura("Divine Purpose")) &&
                !CastingorGCDL() &&
                !Me.CurrentMap.IsDungeon &&
                !Me.CurrentMap.IsRaid &&
                UnitHeal != null &&
                UnitHeal.IsValid &&
                UnitHeal.HealthPercent <= THSettings.Instance.SWordofGloryFriendRet &&
                MyAuraTimeLeft(114163, UnitHeal) < 2000, //114163 Eternal Flame
               
                new Action(delegate
                               {
                                   //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                   CastSpell("Word of Glory", UnitHeal);
                               })
                );
        }

        #endregion

        #region WriteDebug

        public DateTime LastWriteDebug;
        public bool WriteDebugEnable = false;

        private Composite WriteDebug(string message)
        {
            return new Decorator(ret => WriteDebugEnable,
                                 new Action(delegate
                                                {
                                                    Logging.Write("(" +
                                                                  Math.Round(
                                                                      (DateTime.Now - LastWriteDebug).TotalMilliseconds,
                                                                      0) +
                                                                  ") " + message);
                                                    LastWriteDebug = DateTime.Now;
                                                    return RunStatus.Failure;
                                                }));
        }

        #endregion
    }
}